先看第一种做法:
body{
background:url(img.jpg);
background-position:center;
background-repeat:no-repeat;
}
如果图片太小怎么办?
利用一个DIV层,在里面装载一个IMG标签。然后设置DIV和IMG的大小为100%,并固定到屏幕最底层,这样就实现了完美的拉伸并最大化图片的目的。
首先在Body中加入下面的代码:
代码如下:
<div id="div1"><img src="img.jpg" /></div>
然后加入CSS代码:
div#div1{
position:fixed;
top:0;
left:0;
bottom:0;
right:0;
z-index:-1;
}
div#div1 > img {
height:100%;
width:100%;
border:0;
}
body{
background:url(img.jpg);
background-position:center;
background-repeat:no-repeat;
}
如果图片太小怎么办?
利用一个DIV层,在里面装载一个IMG标签。然后设置DIV和IMG的大小为100%,并固定到屏幕最底层,这样就实现了完美的拉伸并最大化图片的目的。
首先在Body中加入下面的代码:
代码如下:
<div id="div1"><img src="img.jpg" /></div>
然后加入CSS代码:
div#div1{
position:fixed;
top:0;
left:0;
bottom:0;
right:0;
z-index:-1;
}
div#div1 > img {
height:100%;
width:100%;
border:0;
}