Published in: CSS
Taken from Dead Centre. Adjust #content depending on the size div you need.
body { margin: 0px } #horizon { color: white; background-color: #0ff; text-align: center; position: absolute; top: 50%; left: 0px; width: 100%; height: 1px; overflow: visible; visibility: visible; display: block } #content { position: absolute; left: 50%; width: 250px; /* Overall width of div */ height: 70px; /* Overall height of div */ top: -35px; /* half of the overall height */ margin-left: -125px; /* half of the overall width */ visibility: visible }
Comments
Subscribe to comments
You need to login to post a comment.

i have a better way that doesn't depend on the width. put a DIV inside a DIV. first DIV is "position:fixed/absolute", the inner one is "margin:0 auto".
anyway, this is good for things with known HEIGHT, cause you need to calculate and cut by half..
Centering a div is a lot less complicated than this. Simply apply a fixed width to your div i.e div { width: 740px; } and add margin: auto; That's it!
div { width: 740px; margin: auto; }
I think it's a way of centering something in the exact middle of a browser window, as opposed to just a center column. Like a picture. Dead center in the middle of your window. Something that was really easy to do with tables. Before they were outlawed...