Search code examples
htmlcsscenteringnested

Centering child div to parent div


This should work. I just want that the nested div is in the center of the parent div. Is this at least the correct approach to center something, or am I way off the standards? I'm just beginning to build my websites.

#container {
    position:relative;
    width:980px;
    height:900px;
    margin:auto;
    border:1px solid red;
}

#logo {
    width:960px;
    height:305;
    margin: 0 auto;
    position:absolute;
}

and the markup

<body>
   <div id = "container">
        <div id = logo><img src="img/johndoe.jpg" width="960" height="305"/></div>
   </div><!-- end of container -->
</body>

Actually, the nested div is at the leftmost of the container.


Solution

  • Remove position:absolute; for the logo.