用定位结合转换中的移动,记着用定位的时候不要忘了子绝父相(小盒子加绝对定位,大盒子加相对定位)
例如:.
big {
position: relative;
width: 300px;
height: 300px;
background-color: red;
}
.small {
position: absolute;
left: 50%;
top: 50%;
background-color: blue;
transform: translate(-50%,-50%);
}
若要使文字垂直水平居中应该这样:
加一个text-align: center;
这是使文字水平居中.
若要使文字在盒子中居中则须使行高等于盒子的行高,即:line-height: 盒子行高;