Skip to content

Instantly share code, notes, and snippets.

@dotmaster
Created December 7, 2010 13:12
Show Gist options
  • Save dotmaster/731777 to your computer and use it in GitHub Desktop.
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
.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
}
}
}
@dotmaster
Copy link
Author

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