//dt 中 img 垂直居中html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<style type="text/css">
div {
display:table-cell;
height:300px;
width:500px;
text-align:center;
border:1px solid #000;
vertical-align:middle
}
</style>
<!--[if IE]>
<style type="text/css">
i {
display:inline-block;
height:100%;
vertical-align:middle
}
img {
vertical-align:middle
}
</style>
<![endif]-->
<div>
<i></i>
<img src="http://www.baidu.com/img/logo.gif" alt=""/>
</div> web
//div 中 img 垂直居中瀏覽器
<!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">
.psdthumb { height: 1%; overflow: hidden; display:table; border-spacing:10px; }
.psdthumb li {border:1px solid #aaa; width:240px; height:160px; text-align:center; vertical-align:middle; position:relative; margin: 10px; *float:left; display: table-cell; }
.psdthumb .qq { *position:absolute; top:50%; }
.psdthumb .qq img { *position:relative; top:-50%; left:-50%; }
</style>
</head>
<body>
<div class="psdthumb">
<li><div class="qq"><img src="wmlogo.gif" ></div></li>
<li><div class="qq"><img src="logo_w.gif" ></div></li>
</div>
</body>
</html>ui
純CSS實現未知尺寸的圖片水平和垂直居中
.box {
/*非IE的主流瀏覽器識別的垂直居中的方法*/
display: table-cell;
vertical-align:middle;
/*設置水平居中*/
text-align:center;
/* 針對IE的Hack */
*display: block;
*font-size:262px;/*約爲高度的0.873,300*0.873 約爲262*/
*font-family:Arial;/*防止非utf-8引發的hack失效問題,如gbk編碼*/
width:400px;
height:300px;
border:1px solid #eee;
}
.box img {
/*設置圖片垂直居中*/
vertical-align:middle;
}
編碼
<div class="box">
<img src="http://www.rainweb.cn/rainweb-blue.png"/>
</div>url