文章详细
CSS未知高度div 垂直居中的问题
 2012/12/8 11:09:52 评论:0人 阅读次数:7936

 网上有很多次讲到过垂直居中的问题,但我觉得还不是很完美。在这里介绍了一种CSS让未知高度的DIV在浏览器中垂直居中。页面随缩小放大而距中,当然如果DIV太大最后以DIV最宽为最小宽度。
效果如图所示:

CSS布局技巧:未知高度div 垂直居中的问题

<!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=utf-8" />
<title>CSS布局技巧:未知高度div 垂直居中的问题 www.ok22.org </title>
<style type="text/css">
html,
body
{
  height: 100%;
  padding:0;
  margin:0;
}

body
{
  min-height: 200px;
  text-align: center;
  min-width: 402px
}
.FirstDIV
{
  margin-top: -100px; /* SecondDIV高度的一半  */
  float: left;
  width: 100%;
  height: 50%;
}
.SecondDIV
{
  clear: both;
  border: silver 1px solid;
  background: #666;
  margin-left: auto;
  font-size:12px;
  width: 700px;
  margin-right: auto;
  height: 200px;
  text-align: left
}
</style>
</head>
<body>
<div class="FirstDIV"></div>
<div class="SecondDIV">
    <p>看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org </p>
    <p>看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org</p>
	<p>看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org</p>
	<p>看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org</p><p>看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org看看,这不就居中了。呵呵。而且没有问题哦。www.ok22.org</p>
</div>
</body>
</html>
如需转载请注明出处:http://www.86y.org/art_detail.aspx?id=496【CSS未知高度div 垂直居中的问题】幸凡学习网
0
 
相关文章
推荐文章
Created By Charry-May 3,2010
粤ICP备10093478号-1
顶部