Skip to content

Instantly share code, notes, and snippets.

@muratpurc
Created September 22, 2011 10:39
Show Gist options
  • Save muratpurc/1234513 to your computer and use it in GitHub Desktop.
Save muratpurc/1234513 to your computer and use it in GitHub Desktop.
HTML/CSS: Center a div vertically and horizontally
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>How to center a div vertically and horizontally</title>
<style type="text/css">
#centerBox {
position: absolute;
width: 600px;
height: 480px;
top:50%;
left:50%;
margin-left:-300px;
margin-top:-240px;
border:1px solid black;
background:#dadada;
}
</style>
</head>
<body>
<div id="centerBox">
Lorem ipsum...
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment