本文翻译自:Expanding a parent
to the height of its children
I have a page structure similar to this: 我有一个类似于此的页面结构:
<body>
<div id="parent">
<div id="childRightCol">
/*Content*/
</div>
<div id="childLeftCol">
/*Content*/
</div>
</div>
</body>
Can you please help me with the CSS for this? 您能帮我用CSS吗?
#1楼
#2楼
I use this CSS to parent and it works: 我使用此CSS作为父项,并且可以正常工作:
min-height:350px;
background:url(../images/inner/details_middle.gif) repeat-y 0 0 ;
padding:5px 10px;
text-align:right;
overflow: hidden;
position: relative;
width: 100%;
#3楼
#4楼
As Jens said in comment 正如詹斯在评论中所说
This works far better for me in all browsers. 在所有浏览器中,这对我来说都更好。
#5楼
#childRightCol:before { display: table; content: " "; }
#childRightCol:after { display: table; content: " "; clear: both; }
#childLeftCol:before { display: table; content: " "; }
#childLeftCol:after { display: table; content: " "; clear: both; }
#6楼
Does this do what you want? 这是您想要的吗?
.childRightCol, .childLeftCol
{
display: inline-block;
width: 50%;
margin: 0;
padding: 0;
vertical-align: top;
}