Created
September 22, 2011 10:39
-
-
Save muratpurc/1234513 to your computer and use it in GitHub Desktop.
HTML/CSS: Center a div vertically and horizontally
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 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