Skip to content

Home

Display table centering

Vertically and horizontally centers a child element within its parent element, using display: table.

<div class="container">
  <div class="center"><span>Centered content</span></div>
</div>
.container {
  border: 1px solid #9C27B0;
  height: 250px;
  width: 250px;
}

.center {
  display: table;
  height: 100%;
  width: 100%;
}

.center > span {
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}

More like this

Start typing a keyphrase to see matching snippets.