日期:2014-05-16 浏览次数:20421 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>无标题页</title>
</head>
<body>
<img src="http://avatar.csdn.net/4/A/C/2_aspwebchh.jpg" id="img1" />
<script>
var img = document.getElementById( 'img1' );
var width = img.offsetWidth;
var height = img.offsetHeight;
img.style.cssText = 'position:absolute;left:50%; top:50%; margin-top:-' + (height / 2) + 'px; margin-left:-' + (width/2) + 'px';
</script>
</body>
</html>