Last active
August 29, 2015 14:06
-
-
Save davorbadrov/7314bfcf1f8706ba2bce to your computer and use it in GitHub Desktop.
Vertically center content using pseudo elements
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="box">OMG! I'm centered!</div> | |
</div> | |
</body> | |
</html> |
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
.container { | |
background: yellow; | |
display: block; | |
width: 300px; | |
height: 300px; | |
white-space: nowrap; | |
overflow: hidden; | |
} | |
.box { | |
width: 150px; | |
text-align: center; | |
} | |
.container:after { | |
content: ''; | |
display: inline-block; | |
height: inherit; | |
vertical-align: middle; | |
width: 0; | |
} | |
.container .box { | |
display: inline-block; | |
white-space: normal; | |
width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment