当前位置: 代码迷 >> HTML/CSS >> 如何让DIV自己伸缩
  详细解决方案

如何让DIV自己伸缩

热度:434   发布时间:2013-12-19 00:33:34.0
怎么让DIV自己伸缩?

    <div style=" width:810px; background-color:#06F; min-height:210px;word-wrap:break-word;">
     <div style="width:200px; height:200px; background-color:#0F0; float:left;">1</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">2</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">3</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">4</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">5</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">6</div>
    </div>

让外面那个大的DIV自动伸缩高度,里面的小DIV走的是数据库,数量不一定,可能多,可能少。

------解决方案--------------------
外面加样式
overflow:hidden
------解决方案--------------------
不设置高度就可以吧,把那个min-height去掉试试?
------解决方案--------------------

       <div style=" width:810px; background-color:#06F; min-height:210px;word-wrap:break-word;">
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">1</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">2</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">3</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">4</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">5</div>
        <div style="width:200px; height:200px; background-color:#0F0; float:left;">6</div>
        <div style="clear:both;"></div>
    </div>

在最后加一个div,做浮动清除,要不然父元素不会自动适应的。
  相关解决方案