用CSS让网页背景图片居中的方法
让背景图片居中的第一个方法是用像素设定,很多都用这种,但是也是最麻烦的:
<div style="width:800px;height:600px;background:url(http://www.siviy.com/images/Package1.jpg) no-repeat 250px 270px;border:1px solid #cccccc;"></div>
第二种居中方法:用50%设定,很方便:
<div style="width:800px;height:600px;background:url(http://www.siviy.com/images/Package1.jpg) no-repeat 50% 50%;border:1px solid #cccccc;"></div>
第三种:用center设定(第2个center可以省略)
<STYLE TYPE="text/css">
<!--
BODY {background-image: URL(http://www.siviy.com/images/Package1.jpg);
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;}
-->
</STYLE>
page:
[1]