Skip to content

Instantly share code, notes, and snippets.

@maxparm
Created August 11, 2012 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxparm/3326245 to your computer and use it in GitHub Desktop.
Save maxparm/3326245 to your computer and use it in GitHub Desktop.
Center vertically any content in CSS
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
​.wrapper {
height:200px;
border:2px solid #CCC;
background:#eee;
}
.vertically-centered {
display:table;
height:100%;
width:100%;
}
.vertically-centered div {
display:table-cell;
height:100%;
width:100%;
vertical-align:middle;
text-align:center;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="vertically-centered">
<div><span>centered content<span></div>
</div>
</div>​
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment