I have tried about 6 different methods and have not been able to get this to work.
I am trying to center the “div.content” horizontally on the page while using position:absolute;
This method works in all browsers, but if you shrink the page size, a scroll bar appears at the bottom:
HTML:
<div class="wrapper">
<div class="header"></div>
<div class="footer"></div>
<div class="content">
<div class="content2">CENTER THIS DIV</div>
</div>
</div>
CSS:
div.header {
background:url('http://i.istockimg.com/file_thumbview_approve/11670843/2/stock-illustration-11670843-seamless-wallpaper-background-tile.jpg') top center repeat-x;
height:150px;
}
div.footer {
background:url('http://www.featurepics.com/FI/Thumb300/20081029/Blue-Tile-Background-947601.jpg') top left repeat-x;
height:150px;
}
div.content {
position:absolute;
top:20px;
left:50%;
height:250px;
width:300px;
}
div.content2 {
position:relative;
left:-50%;
background:white;
height:250px;
}
I would recommend using negative margin like this: http://jsfiddle.net/joshnh/HFwMT/
Here is the adjusted code:
HTML:
CSS: