Skip to content

Instantly share code, notes, and snippets.

@uangsl
Last active January 19, 2018 06:10
Show Gist options
  • Select an option

  • Save uangsl/0ac78810250fedae64a691aa95a03f2c to your computer and use it in GitHub Desktop.

Select an option

Save uangsl/0ac78810250fedae64a691aa95a03f2c to your computer and use it in GitHub Desktop.
css vertical-align middle
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