You can also grab CSS display: table and display: table-cell for this purpose. HTML will look like this:
<body> <div id="body"> </div> </body>
And CSS:
html, body { width: 100%; height: 100%; } html { display: table; } body { display: table-cell; vertical-align: middle; }
If you also want horizontal centering, add the following:
#body { max-width: 1000px; margin: 0 auto; }
Some would call it CSS abuse, but:
- It will work exactly the same almost everywhere.
- Minimal markup and styling required.
- And CSS vertical alignment deserves a bit of abuse; vertical alignment should not require hacking, distortion and the absolute size that it does.
Literature:
mu is too short
source share