Created
May 2, 2016 02:21
-
-
Save z2015/8c8c6bc48dd56b13d453b44683c8867b to your computer and use it in GitHub Desktop.
两种实现css垂直居中vertical-align的方法
This file contains 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*/ | |
div { | |
display: table-cell; | |
vertical-align: middle; | |
} | |
/*#2*/ | |
<h3>With an added pseudo element it's possible</h3> | |
<div class="block2"><div class="inner">Inline-Block</div></div> | |
/* With an added fake (pseudo) element it works */ | |
.block2 { | |
background: orange; | |
height: 80px; | |
} | |
/* Fake (pseudo) element, that enables vertical-align */ | |
.block2:before { | |
content: ""; | |
display: inline-block; | |
vertical-align: middle; | |
height: 100%; | |
} | |
.inner { | |
display: inline-block; | |
vertical-align: middle; | |
background: yellow; | |
padding: 3px 5px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment