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>无标题文档</title>
<style type="text/css">
*{ margin:0; padding:0;}
.one{ width:200px; height:200px; background:blue; position:absolute; top:50%; left:50%;margin:-100px 0 0 -100px; color:#FFF;}
p{ margin:0 auto; width:300px; height:28px; line-height:28px;/*line-height:28px;就是使文字垂直居中*/ background:red;}
</style>
</head>

<body>
<div class="one">这是一个层垂直水平居中与浏览器</div>
<p>段落内文字垂直居中段落内文字垂直居中</p>
</body>

</html>
posted on 2011-03-23 10:54  念时  阅读(391)  评论(0编辑  收藏  举报

细节决定成败!态度决定一切!