/ Published in: CSS
URL: http://stylizedweb.com/2008/02/01/vertical-align-div/
the best solution for vertical align
Expand |
Embed | Plain Text
<div id=”shim”/></div> <div id=”wrapper”> Content </div> html, body { height: 100%; margin: 0; padding: 0; } * { margin:0px auto; padding:0; } div#shim { visibility: hidden; width: 100%; height: 50%; margin-top: -200px; float: left; } div#wrapper { width: 1000px; height: 400px; clear: both; background:red; position: relative; top: -200px; /* IE4ever Hack: Hide from IE4 **/ position: static; /** end hack */ } /* Hide from IE5mac \*//*/ div#shim { display: none; } html, body { height: auto; } /* end hack */ /* ]]> */
Comments
Subscribe to comments
You need to login to post a comment.

Hello ,
I do not agree ,
the real best way to center align one or more block elements in a page(body) is actually to use a real html table structure , it will works then in any browsers (with a minimum css rules) .
The worse is to use negative margin and absolute positionning without min-width and min-height .... just because part of your page can slide of top and left side of your screen with no ways to reach or read it from screen ! (this should never happens !, unless you page is just for google or else search engines )
in between and with css you can have other options : display:table ; display:inline-block and auto margin with absolute positionning . You even have a mix of absolute & relative with negative margin , but really not nice enough in IE7 to talk about ... i leave aside , no need to bring extra confusion :) .
I propose 5 (known i believe) ways to vertical center a page or a block (including table , the most solid solution) I you read french , then go to that page to have an overview : -http://yidille.free.fr/plux/valign/?10-5-pistes-pour-centrer-en-xy-vos-pages
else here are the basic valid (standard render mode) html templates : the single td table : -http://yidille.free.fr/plux/valign/uploads/centre-tableau.html the CSS display:table with IE fixe : -http://yidille.free.fr/plux/valign/uploads/centre-table-css.html (will work in IE 8 without a fix) the inline-block technique (IE
sorry , my post has been squezzed for some unknown reason So I repeat and hoppefully add what is missing:
here are the basic valid (standard render mode) html templates : fluide or fixed ' height' content: the single td table : -http://yidille.free.fr/plux/valign/uploads/centre-tableau.html the CSS display:table with IE fixe : -http://yidille.free.fr/plux/valign/uploads/centre-table-css.html (will work in IE 8 without a fix) the inline-block technique (IE very simply fixed) -http://yidille.free.fr/plux/valign/uploads/centre-inline-stack.html
Fixed 'height' content:
auto-margin with absolute positionning (IE alternative) : -http://yidille.free.fr/plux/valign/uploads/centre-position-absolute.html
Negative margin / absolute positionning with min-height & min-width (fixed for IE6) : -http://yidille.free.fr/plux/valign/uploads/centre-position-absolute-marge-negatives.html
Use the browser of your choice to check those poges out :)
Regards and respects GC