CSS Layout How to - Vertically centring two paragraphs








Question

We would like to know how to vertically centring two paragraphs.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--   www.  ja v a 2s .c  o m-->
  display: table-cell;
  vertical-align: middle;
  border: 1px dotted gray;
  height: 200px;
}
</style>
</head>
<body>
  <div>
    <p>First paragraph.</p>
    <p>Second paragraph.</p>
  </div>
</body>
</html>

The code above is rendered as follows: