就像标题所示,我试图将一个绝对定位的元素水平和垂直居中。根据我发现的其他帖子,这是我尝试的一个缩影。目的是使红色的ALERT文本在轮廓框内居中。
这是CSS:
.parent {
position: relative;
}
.child {
bottom: 0;
color: red;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
}
尝试将绝对父级定位(您必须设置一个高度):
.container {
position: relative;
border: 1px solid black;
}
.parent {
position: absolute;
bottom: 0;
color: red;
left: 0;
top: 0;
right: 0;
width: 100%;
height: 16px;
margin: auto;
text-align: center;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句