Last active
January 19, 2018 06:10
-
-
Save uangsl/0ac78810250fedae64a691aa95a03f2c to your computer and use it in GitHub Desktop.
css vertical-align middle
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
| 1. Using transform and top | |
| .valign { | |
| position: relative; | |
| top: 50%; | |
| transform: translateY(-50%); | |
| /* vendor prefixes omitted due to brevity */ | |
| } | |
| 2. Using inline-block (pseudo-)elements | |
| .parent { | |
| text-align: left; | |
| position: absolute; | |
| height: 56px; | |
| background-color: pink; | |
| white-space: nowrap; | |
| font-size: 0; /* remove the gap between inline level elements */ | |
| } | |
| .dummy-child { height: 100%; } | |
| .valign { | |
| font-size: 16px; /* re-set the font-size */ | |
| } | |
| .dummy-child, .valign { | |
| display: inline-block; | |
| vertical-align: middle; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment