Page Widget How to - Align vertically text within a block element








Question

We would like to know how to align vertically text within a block element.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!-- ww w .j av  a 2 s.  c o m-->
  height: 100px; /* or whatever % etc. */
  border: solid 1px black;
  vertical-align: middle;
  display: table-cell;
}
</style>
</head>
<body>
  <div>Vertically Aligned Text</div>
</body>
</html>

The code above is rendered as follows: