>  기사  >  웹 프론트엔드  >  怎么让DIV自己伸缩?_html/css_WEB-ITnose

怎么让DIV自己伸缩?_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-21 09:47:451332검색

    <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,做浮动清除,要不然父元素不会自动适应的。

       <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,做浮动清除,要不然父元素不会自动适应的。
我擦这是为什么???

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.