Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the least horrible way to center an element with CSS?
    text
    copied!<p>I have html that looks like this:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;!--[if lte IE 8]&gt; &lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt; &lt;![endif]--&gt; &lt;/head&gt; &lt;body&gt; &lt;header&gt; &lt;h1&gt;Some title thing, who knows&lt;/h1&gt; &lt;nav&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="one/"&gt;One&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="two/"&gt;Two&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="three/"&gt;Three&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;/header&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If I give <code>header</code> an auto margin and a width, it's horizontally centered. What's the least horrible way to ensure that it's vertically centered, as well?</p> <p>I am aware of the following articles which provide some discussion of the topic:</p> <ul> <li><a href="http://blog.themeforest.net/tutorials/vertical-centering-with-css/" rel="noreferrer">http://blog.themeforest.net/tutorials/vertical-centering-with-css/</a></li> <li><a href="http://www.vanseodesign.com/css/vertical-centering/" rel="noreferrer">http://www.vanseodesign.com/css/vertical-centering/</a></li> <li><a href="http://www.jakpsatweb.cz/css/css-vertical-center-solution.html" rel="noreferrer">http://www.jakpsatweb.cz/css/css-vertical-center-solution.html</a></li> <li><a href="http://www.brunildo.org/test/vertmiddle.html" rel="noreferrer">http://www.brunildo.org/test/vertmiddle.html</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload