如何使用CSS使网页背景图片延伸

html-css08

如何使用CSS使网页背景图片延伸,第1张

背景色渐变两种方法:1,做一个竖的细条gif,颜色从上到下渐变.以此作背景图.背景图片的颜色无法无限延伸,因为gif长度有限;2,css滤镜做背景色渐变如下,背景颜色渐变可以无限延伸:程序代码<style type="text/css"

想要让图片不变形,就得用JS控制,让它等比例缩放

下面给出一段等比例缩放图片的代码,供参考

/*图片按比例缩放*/

function DrawImage(MyPic,W,H){

var flag=false

var image=new Image()

image.src=MyPic.src

if(image.width>0 &&image.height>0){

flag=true

if(image.width/image.height>= W/H){

if(image.width>W){

MyPic.width=W

MyPic.height=(image.height*W)/image.width

}

else{

MyPic.width=image.width

MyPic.height=image.height

}

}

else{

if(image.height>H){

MyPic.height=H

MyPic.width=(image.width*H)/image.height

}

else{

MyPic.width=image.width

MyPic.height=image.height

}

}

}

}

调用方法如下:

<img src="/图片路径" onload="DrawImage(this,图片宽度尺寸,图片高度尺寸)" border="0" >。