我有这个简单的标记和CSS以垂直对齐框
可以正常运行,并且可以在FF中正常运行,但在Chrome上却无法使用。关于这种情况为什么发生以及如何解决的任何想法?
HTML:
<div id="container">
<div id="box"></div>
</div>
CSS:
#container
{
position: fixed;
top: 25px;
right: 25px;
bottom: 25px;
left: 25px;
border: 1px solid red;
}
#box
{
height: 150px;
margin: -75px auto 0;
position: relative;
text-align: center;
top: 50%;
width: 75%;
border: 1px solid blue;
}
内容: http : //jsfiddle.net/5fLr00tf/
Firefox输出:
Chrome输出:
你忘了添加position: absolute;
的#box
,你也忘了给left: 12.5%;
,这是需要水平居中:
#box {
height: 150px;
margin: -75px auto 0;
position: relative;
text-align: center;
top: 50%;
left: 12.5%;
width: 75%;
border: 1px solid blue;
position: absolute;
}
小提琴:http : //jsfiddle.net/3ya0ewky/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句