A Pen by Joe Richardson on CodePen.
Created
February 16, 2017 01:48
-
-
Save rafszul/d0eb346073505f24b8e6c02cacc4c994 to your computer and use it in GitHub Desktop.
Vertically and horizontally aligned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="table-cell"> | |
| <h1 class="element">Table Cell</h1> | |
| </div> | |
| <div class="flex"> | |
| <h1>Flex</h1> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .table-cell { | |
| width: 100%; | |
| display: table; | |
| height: 100%; | |
| margin: 0 auto; | |
| .element { | |
| display: table-cell; | |
| vertical-align: middle; | |
| text-align: center; | |
| } | |
| } | |
| .flex { | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| height: 100%; | |
| } | |
| // Demo Content | |
| html, | |
| body { | |
| height: 100%; | |
| } | |
| div { | |
| &:nth-child(1) { | |
| background: yellow; | |
| } | |
| &:nth-child(2) { | |
| background: salmon; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment