I am trying to negatively position a DIV element (in the #content example), but my problem is the div container (# wrapper2) gets too high (actually this is the height that #content gives, but since I move the content up, I would like reduce the height of # wrapper2 accordingly).
Here I give you an example to show what I'm trying to achieve. If you try the sample, you will see that the footer is too far from the container. I can make a dirty hack here and make the top of the footer: -200px too, but then the scroll bar of the window goes over the footer.
<!DOCTYPE html> <html> <head> <title>Relative positioning demo</title> <style> html { margin:0; padding:0; border:0; } body, div, p, h1 { margin: 0; padding: 0; border: 0; } h1 { background-color: yellow; } p { margin-bottom: 1em; } #wrapper1 { text-align: center; height: 250px; background-color: lightgray; } #wrapper2 { background-color: lightblue; } #content { width: 950px; margin: 0 auto; background-color: white; padding: 5px; height: 560px; position: relative; top: -200px; } #footer { background-color: black; color: white; height: 40px; line-height: 40px; text-align: center; } </style> </head> <body> <div id="wrapper1"> <h1>This is my heading</h1> </div> <div id="wrapper2"> <div id="content"> My content here </div> </div> <div id="footer"> lorem ipsum </div> </body> </html>
If you have any suggestions, keep in mind that I should see both a light and a light background (these are images on my website), so margin-top: -200px is not an option (for example, someone suggested in related questions I was looking for)
Thanks!
source share