将父div展开为子高 [英] Expand Parent Div To Child Height

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

问题描述

我有一个类似这样的页面结构:

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

我想为父 div 当内部 div 高度展开时,在 height / p>

编辑

一个问题是如果 width 的子内容扩展到浏览器窗口的 width 之后,我当前的CSS将一个水平滚动条放在父 div 。我想滚动条在页面级别。目前我的父div设置为 overflow:auto;



你能帮我使用CSS吗?

解决方案

尝试这样做的父母,它为我工作。

  overflow:auto; 

更新:



还有一个解决方案:



  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 height expands.

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;

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

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