Web developer, Norwich - Clive Portman

Center element vertically and horizontally using CSS

Published under CSS

Published on Saturday 16th June 2012

Use fixed positioning combined with negative margins:

#whatever {
position: fixed; top: 50%; left: 50%;
width: 800px; height: 400px;
margin-left: -400px; margin-top: -200px;
}

Note the negative margins are exactly half the width/height.