CSS - 将子DIV高度浮动到父级高度 [英] CSS - Expand float child DIV height to parent's height

查看:76
本文介绍了CSS - 将子DIV高度浮动到父级高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面结构为:

<div class="parent">
    <div class="child-left floatLeft">
    </div>

    <div class="child-right floatLeft">
    </div>
</div>

现在,子元素 DIV将会有更多的内容,所以 DIV的高度根据子DIV增加。

Now, the child-left DIV will have more content, so the parent DIV's height increases as per the child DIV.

但问题是 child-right height没有增加。如何让它的高度等于它的父级?

But the problem is child-right height is not increasing. How can I make its height as equal to it's parent?

推荐答案

为父元素添加以下属性

.parent {
    overflow: hidden;
    position: relative;
    width: 100%;
}

然后用于 .child-right b
$ b

then for .child-right these:

.child-right {
    background:green;
    height: 100%;
    width: 50%;
    position: absolute;
    right: 0;
    top: 0;
}

你可以在这里找到更详细的CSS例子: http://jsbin.com/nimeguxuda/1/edit?html,css,output

You can find more detailed results with CSS examples here: http://jsbin.com/nimeguxuda/1/edit?html,css,output

您可以在 http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks

这篇关于CSS - 将子DIV高度浮动到父级高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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