This question is not a duplicate. I tried other methods and they didn't work correctly!
What I am trying to do:
I am trying to put a container div (600x600) right in the middle of the webpage, both vertically and horizontally.
What is happening:
The div only centers horizontally, but not vertically.
What I have tried:
I've followed a few methods. One of which puts another div outside of the container, which is set to display:table, then the container is a table cell. This didn't work.
I also just tried using this which another stackoverflow post suggested:
position:absolute;
left:0; right:0;
top:0; bottom:0;
margin:auto;
This also did nothing for me.
FIDDLE: http://jsfiddle.net/ULHbt/1/
HTML:
<div id="container">
<div id="largeLogo">Logo</div>
<div id="redBanner"></div>
</div>
CSS:
body {
background-color:#d7d7d7;
}
#container {
margin:0 auto;
width:600px;
height:600px;
border:1px solid;
background-repeat:no-repeat;
background-position:center;
top:50%;
}
#largeLogo {
position:relative;
top:167px;
width:502px;
height:40px;
margin: 0 auto;
border:1px solid;
}
#redBanner {
top:326px;
position:absolute;
width:100%;
background-color:#d2232a;
height:42px;
left:0;
right:0;
}