Skip to content

Instantly share code, notes, and snippets.

@caok
Created November 19, 2013 08:32
Show Gist options
  • Save caok/7542143 to your computer and use it in GitHub Desktop.
Save caok/7542143 to your computer and use it in GitHub Desktop.
其实解决的思路是这样的:首们需要position:absolute;绝对定位。而层的定位点,使用外补丁margin负值的方法。负值的大小为层自身宽度高度除以二。
<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>
@caok
Copy link
Author

caok commented Jan 15, 2014

左右居中

body {
text-align: center;
}

wrap {

margin-left: auto;
margin-right: auto;
}

@caok
Copy link
Author

caok commented Nov 5, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment