你的位置:首页 > 网页设计

[网页设计]未知图片大小的自动水平和垂直居中方法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html <head>
<title>图片自动垂直居中</title>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8" />
<style type="text/css">
<!--
ul#FgWrap{width: 936px;margin: 0 auto;list-style: none;padding-top: 2em;}
ul#FgWrap li{float: left; margin: 0 10px 10px 0;background: #EEE}
.boxinner{
height:160px;
width:200px;
border: solid 1px #666;
text-align:center;
display:table-cell;
vertical-align:middle;
}
.boxinner img {margin:0 auto;border: 4px solid #FFF;}
-->
</style>
<style type="text/css">
/* IE下的垂直居中*/
.edge {width:0; height:100%; display:inline-block; vertical-align:middle;}
.container {text-align:center; width:100%; display:inline-block; vertical-align:middle;line-height:80%;}
/*加上line-height:80%主要是消除在IE-Firefox-Chrome三个浏览器图片下方多出的空白,使图片四周空白宽度一样*/
</style>
</head>
<body>
<div>http://www.999jiujiu.com/</div>
<div id="forestganMiddle">
<ul id="FgWrap">
<li>
<div ><span ></span><span ><img alt="" src="wall_s3.jpg" /></span></div>
</li>
<li>
<div ><span ></span><span ><img height="40" alt="" width="65" src="wall6.jpg" /></span></div>
</li>
</ul>
</div>
</body>
</html>