Parent-child height problem

Posted by Vector on Stack Overflow See other posts from Stack Overflow or by Vector
Published on 2011-01-15T03:03:44Z Indexed on 2011/01/15 3:53 UTC
Read the original article Hit count: 193

Filed under:

I have a parent div that has position: relative and his child has position: absolute. Such positions is a must. The problem is the parent does not stretch to the height of the child. The question is how to make it stretch to the height of the child?

The mark-up is similar to this:

<!DOCTYPE HTML>
<html>
    <head>
        <style>
            .parent {
                position: relative;
                border: solid 1px red;
            }

            .child {
                position: absolute;
                border: solid 1px red;
            }
        </style>
    </head>
    <body>
        <div class="parent">
            <div class="child">Hello World!</div>
        </div>
    </body>
</html>

© Stack Overflow or respective owner

Related posts about css