中国.Rick

IT.Man

DIV父容器高度控制

Div即父容器不根据内容自适应高度,我们看下面的代码:

程序代码

<div id="main">
<div id="content"></div>
</div>

当Content内容多时,即使main设置了高度100%或auto。在不同浏览器下还是不能完好的自动伸展。内容的高度比较高了,但容器main的高度还是不能撑开。

我们可以通过三种方法来解决这个问题。
  
一,增加一个清除浮动,让父容器知道高度。请注意,清除浮动的容器中有一个空格。

程序代码<div id="main">
<div id="content"></div>
<div style="font: 0px/0px sans-serif;clear: both;display: block"> </div>
</div>

二,增加一个容器,在代码中存在,但在视觉中不可见。

程序代码<div id="main">
<div id="content"></div>
<div style="height:1px; margin-top:-1px;clear: both;overflow:hidden;"></div>
</div>

三,增加一个BR并设置样式为clear:both。

程序代码<div id="main">
<div id="content"></div>
<br style="clear:both;" />
</div>  
 

« 上一篇 | 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Walle Build 100427 and Theme By BokeZhuti.cn

Copyright RickC.cn [浙ICP备09040539] Some Rights Reserved.