How to center and vertically align text within a div?
<p>The code below vertically aligns the text within a div perfectly fine but when I try to center it, only the text that needs to be wrapped gets centered. When the text is short, say, 5-6 words, the text is not centered. I don't know if it is just me or I'm doing something wrong here. </p>

<p>I am using  <code>display: table-cell;</code> to do the vertical alignment. Both <code>div</code> and <code>p</code> elements are defined in the CSS the same way. Have a look at the codepen to see the problem.</p>

<pre><code>&lt;style&gt;
  .outer { outline: 1px solid #eee; }
  .outer &gt; p { 
    display: table-cell; 
    height: 200px; 
    vertical-align: middle;
    text-align: center;
  }
&lt;/style&gt;
&lt;div class="outer"&gt;
  &lt;p&gt;
    This longer text will be vertically aligned.
  &lt;/p&gt;
&lt;/div&gt;
&lt;div class="outer"&gt;
  &lt;p&gt;
    This longer text will be vertically aligned and centered. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  &lt;/p&gt;
&lt;/div&gt;
</code></pre>

<p><a href="http://codepen.io/anon/pen/vGowKL" rel="nofollow">http://codepen.io/anon/pen/vGowKL</a></p>