绝对中心流体div [英] Absolute center a fluid div
本文介绍了绝对中心流体div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天。
我知道如果你想绝对地定位一个div,你可以这样做:
I know that if you want to absolute center a div, you do this:
<div id="parent">
<div id="child">blahblah</div>
</div>
CSS:
#parent{
width: 500px;
height: 500px;
position: absolute; /*(or relative)*/
top: 50%;
left: 50%;
margin-top: -250px;
margin-left: -250px;
text-align: center;
}
如果父div是流体div你如何ABSOLUTE中心它的意义:
What if the parent div is a fluid div? How do you ABSOLUTE center it meaning:
#parent{
max-width: 500px;
max-height: 500px;
top: 50%; ->is this right?
left: 50%; -> is this right?
margin-top: ???;
margin-left: ???;
text-align: center;
}
推荐答案
code> flex 来实现这个...
I'll simply use flex
to achieve this...
#parent {
display: flex;
justify-content: center;
}
<div id="parent">
<div id="child">blahblah</div>
</div>
这篇关于绝对中心流体div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文