Created
May 21, 2013 03:23
-
-
Save mjj2000/5617292 to your computer and use it in GitHub Desktop.
[CSS]Center div in div
This file contains hidden or 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
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html> | |
<head> | |
<style> | |
#table{ | |
display:table; /* must be 'table' */ | |
} | |
#table-cell{ | |
position:relative; /* must be 'relative' */ | |
width:500px; /* must be assigned an absolute value */ | |
height:500px; /* must be assigned an absolute value */ | |
display:table-cell; /* must be 'table-cell' */ | |
vertical-align: middle; /* center content div vertically */ | |
background:blue; | |
} | |
#div{ | |
position:relative; /* must be 'relative' */ | |
margin:auto auto; /* center div horizontally*/ | |
width:50%; | |
height:50%; | |
background:red; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="table"> | |
<div id="table-cell"> | |
<div id="div"></div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment