There is only one p in an html.
<p class="test">
</p>
css1:
.test{
width:200px;
height:200px;
border:1px solid red;
margin:0 auto;
}
css1 can center p.test left and right.
css2:
.test{
width:200px;
height:200px;
border:1px solid red;
margin:auto auto;
}
为何css2不可以使p.test上下左右居中??
请不要回答如何使他p.test上下左右居中,请回答为何margin:auto auto;不能上下左右居中??
下面是关于高度的:
因为规范就是这么规定的算法,浏览器就是这么实现的。
CSS规范
This is a good question. Let me ask you, when there are two elements in a row, can you center them left and right? In the same way, when there may be elements above and below you, how do you want the browser to calculate the position where the corresponding element should exist?
No, if you don’t use flex layout for top and bottom alignment, there is no good way. Virtical–align is not easy to use either!
No, if you want to center the top, bottom, left, and right, it is recommended to use flex layout, followed by table, table-cell or positioning