Maison  >  Article  >  interface Web  >  怎么让DIV自己伸缩?_html/css_WEB-ITnose

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

WBOY
WBOYoriginal
2016-06-21 09:47:451333parcourir

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn