垃圾回收站

June 20, 2007

让DIV里面的文字垂直居中

[ 分类: CSS ] 由 弗里曼·潘 发表于 8:39 pm

http://blog.donews.com/dodo/archive/2007/06/20/1177832.aspx

<style type=”text/css”>
<!–
.con_div{
width:400px;
height:300px;
border:1px solid #777;
text-align:center;
display:table-cell;
vertical-align:middle;
background:red;
color:#fff
}
/*FOR IE*/
.fixie{
width:0;
height:100%;
display:inline-block;
vertical-align:middle;
}
–>
</style>
<div class=”con_div”>
<span class=”fixie”></span>
测试内容
</div>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>div里面图片垂直居中的几个例子</title>
<style type=”text/css”>
<!–
* {margin:0;padding:0}
div {
  width:500px;
  height:500px;
  line-height:500px;
  border:1px solid #666;
  overflow:hidden;
  position:relative;
  text-align:center;
}
div p {
  position:static;
  +position:absolute;
  top:50%;
  vertical-align:middle
}
img {
  position:static;
  +position:relative;
  top:-50%;left:-50%;
  vertical-align:middle
}
–>
</style>
</head>
<body>
<div><p><img src=”http://www.google.com/intl/en/images/logo.gif” /></p></div>
</body>
</html>


0 条评论 »

还没有人对这篇文章发表评论,赶紧留一个吧。

RSS feed for comments on this post. TrackBack URI

相关文章:
  • 暂时没有相关的文章
  • 发表评论