I have some HTML codes like
<div id="top" style="height: 50px"></div>
<div id="bottom" style="height: 50px"></div>
<div id="content">Here goes some text</div>
I want the middle div (#bottom) to be positioned on top of the div (#top) and while doing so, the #content div should automatically move up by 50px.
If i code like
<div id="bottom" style="height: 50px; position: relative; top: -50px;"></div>
the #bottom div do moves up but the #content div stays behind.. leaving a 50px gap between.
So how should I position it??
If I’m understanding correctly, you want to take
#bottomand remove it from the regular page flow, placing it over-top-of#top.Two ways to take an element out of the regular page flow are
position:float;andposition:absolute;Not knowing what the rest of your page looks like I suggest something like:
That will put
#bottomin the top, left-hand corner of#container, which is also where#topwill be.#containerbeing part of the regular page flow will be right below#top.For centering an absolutely positioned element you can do like this: