1. 标准流下的盒子居中(只对块元素起作用)
margin: 0 auto;
2. 绝对定位的盒子居中
- 通过具体的计算,让盒子居中.
- 通用的一种用法.
position: absolute; /* 移动父元素宽度的一半 */ left: 50%; top: 50%; /* 移动的是元素本身自己的一半 */ margin-left: -60px; margin-top: -25px;
margin: 0 auto;
position: absolute; /* 移动父元素宽度的一半 */ left: 50%; top: 50%; /* 移动的是元素本身自己的一半 */ margin-left: -60px; margin-top: -25px;