我希望文章的 div(白色内容和右侧灰色列)将随着白色文本的高度而扩展。
我试图添加clear:both
到#bodycont,但它没有帮助
我怎样才能使它灵活?
clear: both;
is to be added AFTER using floats: placing it on #bodycont
would be useful if your header had floats (I didn't check). Placing it on the parent will do nothing (though there're other methods where the selector begins with this parent, namely parent:after { /* strange bunch of instructions working in IE8 and above */ }
, but that's not the parent itself)
Some general instructions:
height
property on columns or layout blocks.height
property: particular cases need min-height
when graphical elements are to be displayed entirely (when there's a nice background of known height that shouldn't be cropped), general case is using methods that don't need the height of elements to display properly.clear: both
on the element that follows floating columns or on the sibling of an element that contain floats. In your case the footer.:before
part is only there for consistent collapsing margins, you only need the :after
along with the parent, err betweeen the parent and the next element, that's where :after
is)解决方案是添加display:table
和删除高度。因为允许我根据文本显示高度。
很简单!