Forum Moderators: not2easy
The problem is I have an image, in a DIV, that I need to overlay on top of the page. The problem I'm having is that when I resize the browser window - that image stays in the same place and does not move with the rest of the site. I've tried positioning that div within other divs and changing the position from absolute to relative etc but it still seems to remain static on the page.
Here's the DIV code for the overlaying image:
#image-overlay
{
position: absolute;
top: 34px;
left: 434px;
width: 547px;
height: 58px;
}
I'm sure it's something very, very simply but I'm just not sure what?! Any help would be very much appreciated.
#image-overlay {
top: 50%;
margin-top: -29px; /* half of the height */
left: 50%
margin-left: -274px; /* half of the width */
}
Basically it first move e.g. the left side to the middle (
left: 50%;) and then moves it back for half of the width of the element (negative margin). If you want to center it relative to a parent, make sure the parent has position. Position can be given by e.g. "
position: relative;" without needing to "nudge" it itself using left/top/right/bottom.