Files
30-seconds-of-code/snippets/grid-centering.md
atomiks 39b676c125 Improve usage share count (#138)
* Improve usage share

* Remove 'No caveats' note from all snippets

* Fix transform-centering usage: #search -> #feat

* transform -> transforms2d

* Add missing link for multiline truncate
2019-02-18 04:35:48 +11:00

599 B

Grid centering

Horizontally and vertically centers a child element within a parent element using grid.

HTML

<div class="grid-centering"><div class="child">Centered content.</div></div>

CSS

.grid-centering {
  display: grid;
  justify-content: center;
  align-items: center;
  height: 100px;
}

Demo

Explanation

  1. display: grid enables grid.
  2. justify-content: center centers the child horizontally.
  3. align-items: center centers the child vertically.

Browser support