How do I make a parent/container DIV grow as more children DIV's are added.

当添加更多儿童DIV时,如何使父/容器DIV增长。

<div id="container">
     <div id="child" style="height:100px;">
     </div>
     <div id="child2" style="height:100px;">
     </div>
</div>

4 个解决方案

#1


22

The only reason why your parent div would not grow with its content is if it's content is absolute positioned or is using floats, in the former case there is nothing you can do short of resizing it with javascript, in the latter you can put the following code at the end of your floating elements:

你的父div不会随其内容增长的唯一原因是,如果它的内容是绝对定位或使用浮点数,在前一种情况下你没有什么可以做的,只需用javascript调整它的大小,在后者你可以把以下浮动元素末尾的代码:

<br style="clear: both">

So say both the child elements in your example have a float, the code would look like this

所以说你的例子中的两个子元素都有一个浮点数,代码看起来像这样

<div id="container">
     <div id="child" style="height:100px;">
           ** CONTENT GOES HERE **
           <br style="clear: both">
     </div>
     <div id="child2" style="height:100px;">
           ** CONTENT GOES HERE **
           <br style="clear: both">
     </div>
</div>

You can use any node, as long as you use "clear: both" on it (So <div style="clear: both"></div> would work too).

您可以使用任何节点,只要您使用“clear:both”(So

也可以)。

更多相关文章

  1. 如何使用Watir访问自定义属性的元素?
  2. 【置顶】 不显示删除回复显示所有回复显示星级回复显示得分回复
  3. 在Emacs中将语法突出显示的代码转换为HTML
  4. 禁用div中的所有表单元素
  5. 怎么动态设置html的canvas元素的尺寸?
  6. JQuery基于元素的高度添加类
  7. 单个元素html上的多个类
  8. 样式通常以相同的组合出现:创建单个类还是组合元素?
  9. 在href元素中使用标记<c:out [duplicate]

随机推荐

  1. Android 的系统架构
  2. Android(安卓)模拟器入门
  3. 【源码分享下载】每日更新之Android应用
  4. Android内核开发:开发板选购
  5. Android开发人员必须收藏的国外网站
  6. Android编译系统(四):Android 编译系统框
  7. Android多进程之Binder解绑监听的问题
  8. Android图形显示系统——下层显示3:窗口系
  9. Android硬件控制之USB连接
  10. 如何学习android