最近接到一個Ticket,要求是做一個頁面,然后將里面的一個Div水平垂直在頁面上,廢話不多說,先上代碼
<title>水平垂直居中</title>
<style type="text/css">
<!--
.main
{
position:absolute;
top:50%;
left:50%;
border:1px dotted green;
background-color:#CCFF99;
color:green;
560px;
height:100px;
line-height:100px;
text-align:center;
font-size:12px;
margin:-50px 0 0 -280px;
}
-->
</style>
</head>
<body>
<div class="main">
對不起,您訪問的頁面不存在,請聯系開發人員!
</div>
</body>
相信都看得懂這一些CSS 我分享一下最后一條為什麼這樣寫:
margin:-50px 0 0 -280px;
不加這一條代碼的話,div的左上點是在頁面的中央,-50是高度的一半,-280是寬度的一半,這樣算下來就是在中間了
不知道為什麼我打開這個添加新隨筆的頁面,寫文章時,經常會假死,其它頁面沒有這個情況,我用得是IE8,請知道原因的博友能分享一下原因以及解決方法,謝謝