Skip to content

Instantly share code, notes, and snippets.

@moudy
Created January 27, 2011 15:39
Show Gist options
  • Save moudy/798650 to your computer and use it in GitHub Desktop.
Save moudy/798650 to your computer and use it in GitHub Desktop.
aligns a div vertically on a page
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html,body{
height:100%;
margin:0;
padding:0;}
#offset{
width:100%;
height:50%;
margin-top:-250px; /* half of content height*/
float:left;}
#page {
width:700px;
height:500px;
margin:0 auto;
border:1px solid #444;
overflow:auto; /* allow scrolling in element */
clear:both;}
</style>
</head>
<body>
<div id="offset"></div> <!--invisible, causes following div to be vertically centered-->
<div id="page">
<!--content here-->
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment