Created
November 19, 2013 08:32
-
-
Save caok/7542143 to your computer and use it in GitHub Desktop.
其实解决的思路是这样的:首们需要position:absolute;绝对定位。而层的定位点,使用外补丁margin负值的方法。负值的大小为层自身宽度高度除以二。
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
<style type="text/css"> | |
<!-- | |
div { | |
position:absolute; | |
top:50%; | |
left:50%; | |
margin:-150px 0 0 -200px; | |
width:400px; | |
height:300px; | |
border:1px solid #008800; | |
} | |
--> | |
</style> | |
<div>让层垂直居中于浏览器窗口</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
左右居中
body {
text-align: center;
}
wrap {
margin-left: auto;
margin-right: auto;
}