Ala Ala - 2 months ago 9
CSS Question

Dynamic height for a child div when the position is relative

It seems a duplicated question but unfortunately I didn't find answers for this simple scenario when the

Position
is
Relative
.

I have a parent div with two child divs:

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


where both parent and child divs have a
position:relative;


A Jsfiddle example is HERE

So my question is almost like THIS question but the position is not absolute here.

How do I make the height of
content_rdivider
div the same as the height of the parent div?

Answer

try this

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;
}