61,112
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
#picbox{width:200px;height:200px;background:#ccc;}
#picbox img{width:100px;height:100px;}
</style>
<script>
function setCenter(Xelement)
{
var parent=Xelement.parentNode;
parent.style.position="absolute";
Xelement.style.position="absolute";
var left=(parent.clientWidth-Xelement.clientWidth)/2;
var top=(parent.clientHeight-Xelement.clientHeight)/2;
Xelement.style.left=left+"px";
Xelement.style.top=top+"px";
}
</script>
</head>
<body>
<div id="picbox">
<img id="img1" src="2.jpg" alt="" onload="setCenter(this)"/>
</div>
</body>
</html>
<!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>无标题文档</title>
<style type="text/css">
#picbox{width:400px; height:300px; text-align:center; line-height:300px; border:solid 3px red;}
#picbox span{display:inline-block;}
#picbox img{vertical-align:middle;}
</style>
</head>
<body>
<div id="picbox">
<span> </span><img src="http://imgsrc.baidu.com/forum/pic/item/3cb753af54ac0fc7faed50f1.jpg" />
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
#picbox{width:200px;height:200px;background:#ccc;}
#picbox img{float:left;width:100px;height:100px;margin:50px;}
</style>
</head>
<body>
<div id="picbox">
<img src="2.jpg" alt="" />
</div>
</body>
</html>
<!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>无标题文档</title>
<style type="text/css">
#picbox{width:200px;height:200px;text-align:center; line-height:200px; border:1px #000 solid;}
#picbox img{width:100px;height:100px; vertical-align:middle;}
</style>
</head>
<body>
<div id="picbox">
<img src="" alt="" />
</div>
</body>
</html>