Skip to content

行(行块)盒水平居中 ​

其父元素的 CSS 样式: text-align:center;

常规流块盒水平居中 ​

宽度固定,该元素:margin-left:auto;margin-right:auto;

绝对定位元素的水平居中 ​

宽度固定,该元素 left:0;right:0;margin-left:auto;margin-right:auto;

单行文本垂直居中 ​

设置行高

行块盒/块盒 内多行文本垂直居中 ​

使用 padding,模拟垂直居中的效果

没有完美的方案

绝对定位的垂直居中 ​

高度固定,该元素 top:0;bottom:0;margin-top:auto;margin-bottom:auto;

以笔记为镜,可以知得失