-
[散修弟子]JS-23771
两个例子的区别
HTML:
<div id="centerTest1">
<p>元素水平居中</p>
</div>
<div id="centerTest2">
<p>元素水平垂直居中</p>
</div>
CSS:
/*CSS 居中*/
[id *= "centerTest"] {width: 150px;height: 150px;}
#centerTest1 p {margin: auto;}
#centerTest2 {position: relative;}
#centerTest2 p {
position: absolute;
width: 100px;
height: 20px;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
编辑于2021-07-03
- 去第 页