Skip to content

Instantly share code, notes, and snippets.

@hemantajax
Created June 9, 2012 04:16
Show Gist options
  • Save hemantajax/2899411 to your computer and use it in GitHub Desktop.
Save hemantajax/2899411 to your computer and use it in GitHub Desktop.
Centering div using pure css
<!doctype html>
<html>
<head>
<title>Centering div using pure css</title>
<meta charset="utf-8" />
<style>
.outer{
position: absolute;
top: 50%;
left: 0px;
width: 100%;
height: 1px;
overflow: visible;
}
.inner{
width: 400px;
margin-left: -200px; /* width of the .inner / 2 */
position: absolute;
top: -140px;
left: 50%;
text-align:center;
background-color: #ff0;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner">
<h1>My Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment