中心对齐在绝对定位的Div [英] Center Align on a Absolutely Positioned Div
本文介绍了中心对齐在绝对定位的Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
div#thing
{
position: absolute;
top: 0px;
z-index: 2;
margin: 0 auto;
}
<div id="thing">
<p>text text text with no fixed size, variable font</p>
</div>
div位于顶部,但不能以 < center>
或 margin:0 auto
;
The div is at the top, but I can't center it with <center>
or margin: 0 auto
;
推荐答案
如果您给予 div
固定宽度,您的问题可能会解决,如下所示:
Your problem may be solved if you give your div
a fixed width, as follows:
div#thing
{
position: absolute;
top: 0px;
z-index: 2;
width:400px;
margin-left:-200px;
left:50%;
}
这篇关于中心对齐在绝对定位的Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文