全国热线:0536-8800925
新闻动态

DIV块页面垂直居中方法

    DIV垂直居中,例如后台登录框等使用CSS的Top和Margin属性让DIV垂直居中

    CSS样式

<!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=gb2312" />
<title>DIV垂直居中</title>
<style type="text/css">
<!--
.cr { top:50%; left:50%; margin:-80px 0 0 -140px; width:280px; height:160px; position:absolute; background-color:#CCC }
-->
</style>
</head>

<body>
<div class="cr">测试一下是不是垂直居中了;记得加上position:absolute;</div>
</body>
</html>



 


在线咨询
Tel

0536-8800925

关注我们微信