Created
December 7, 2010 13:12
-
-
Save dotmaster/731777 to your computer and use it in GitHub Desktop.
CSS vertical centering in all major browsers (including ie6) using less css and conditional comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.vcenter{ | |
body{ | |
display: table; | |
.ie6,ie7,ie8,ie9{ //thanks to our conditional comments (see comments below) | |
position: relative; //for ie | |
#container{ | |
position:absolute; //for ie | |
top:50%; //for ie | |
#page{ | |
position:relative; //for ie | |
top:-50%; //for ie | |
} | |
} | |
} | |
#container{ | |
display: table-cell; vertical-align: middle; //vertical alignment for all others | |
} | |
} | |
} |
This less script is based on this blog post http://www.jakpsatweb.cz/css/css-vertical-center-solution.html, but enhances it, cause we use conditional comments to determine the browser we are working with.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how it works:
use a conditional comment in your HTML5 Boilerplate like the following
then create a structure of divs like the following
note that we need at least three levels of nesting for Internet Explorer to work
Some vertically centered content
Now drop in the vcenter class in your less file: