当位置相对时,子div的动态高度

时间:2013-08-02 08:13:44

标签: html css

这似乎是一个重复的问题,但遗憾的是,当PositionRelative时,我没有找到这个简单方案的答案。

我有一个带有两个子div的父div:

<div id="content">
    <div id="content_rdivider">&nbsp;</div>
    <div id="content_right"></div>
</div>

其中父级和子级div都有position:relative;

Jsfiddle示例是HERE

所以我的问题几乎就像THIS问题,但这里的立场并不绝对。

如何使content_rdivider div的高度与父div的高度相同?

1 个答案:

答案 0 :(得分:4)

试试这个

http://jsfiddle.net/9c4MK/15/

CSS

#content {
    position: relative;
    background-color: #FFF;
    width: 975px;
    padding: 0px 0px 0px 0px;
    background-repeat: no-repeat;
    background-position: bottom left;
    border: solid 1px #d7d7d7;
    border-bottom: none;
    margin-left: auto;
    margin-right: auto;
    direction: ltr;
    overflow: hidden;
    height: auto;
    display: table;
}
#content_right {
    width: 180px;
    text-align: right;
    display: table-cell;
}
#content_rdivider {
    width: 10px;
    text-align: center;
    background-color: red;
    position: relative;
    height: 100%;
    display: table-cell;
}