水平居中
行盒(行块盒)
父元素设置text-align:center
常规流块盒:
定宽,设置左右margin为auto
绝对定位元素的水平居中
定宽,left:0, right:0,将左右margin设置为auto
或者设置left: 50%, transform: translateX(-50%)
父元素设置display: flex; justify-content: center
垂直居中
单行文本的垂直居中
设置文本所在元素的行高,为整个区域的高度
绝对定位的垂直居中
定高,设置上下的坐标为0(top:0, bottom:0),将上下margin设置为auto
或者设置top: 50%, transform: translateY(-50%)
行块盒或块盒内多行文本的垂直居中
没有完美方案
设置盒子上下内边距相同,达到类似的效果。