I know how to center a div layer with respect to it’s wrapper or parent container, but what about When I have a div inside of a div inside of the page body. How do I center the smallest div with respect to the body?
<div id="1" style="width: 100%">
<div id="2" style="width: 22.5%; height: 1000000000px; margin-left: 12%;">
<div id="3" style="position: absolute;">
</div>
</div>
</div>
In the above example, How can I center div with id=”3″ in respect to div with id=”1″?
#1must beposition: absolute,#3setleft: 50%and offset half the width to the leftJSFiddle for playing.
I have moved the inline styles to the CSS panel and changed the
ids tod1,d2andd3respectively.