展开父级< div>达到孩子的身高 [英] Expanding a parent <div> to the height of its children

查看:104
本文介绍了展开父级< div>达到孩子的身高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于此的页面结构:

 < body> 
< div id =parent>
< div id =childRightCol>
/ *内容* /
< / div>
< div id =childLeftCol>
/ *内容* /
< / div>
< / div>
< / body>

我想要父母 div 来当内部 div 高度增加时,展开高度

编辑:

一个问题是,如果宽度展开超过了浏览器窗口的宽度,我当前的CSS将水平滚动条放在父元素 div 。我希望滚动条处于页面级别。目前我的父div被设置为 overflow:auto;



你能帮我用CSS吗?

解决方案



 溢出:汽车; 

更新:

另外还有一个解决方案:

家长

  display:table; 

小孩

  display:table-row; 


I have a page structure similar to this:

<body>
  <div id="parent">
    <div id="childRightCol">
      /*Content*/
    </div>
    <div id="childLeftCol">
      /*Content*/
    </div>
  </div>
</body>

I would like for the parent div to expand in height when the inner div's height increases.

Edit:
One problem is that if the width of the child content expands past the width of the browser window, my current CSS puts a horizontal scrollbar on the parent div. I would like the scrollbar to be at the page level. Currently my parent div is set to overflow: auto;

Can you please help me with the CSS for this?

解决方案

Try this for the parent, it worked for me.

overflow:auto; 

UPDATE:

One more solution that worked:

Parent:

display: table;

Child:

display: table-row;

这篇关于展开父级&lt; div&gt;达到孩子的身高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆