The Lab

2. Jan 2012

Vertical centering in CSS

This method centers your content vertically. Unlike some other methods, this works without having to set any height to the centered elements.

html, body { display:table; margin:0; padding:0; width:100%; height:100%; } body { display:table-cell; vertical-align:middle; }


This is actually an old technique by Bert Bos. It validates and still works perfectly!


Test it!

Back to Grimsrud Interaktiv