我想控制网页内图片的大小
希望高度固定在150,宽度按比例自由伸缩,但不得超过200,请问代码
參考答案:float k;
k=Img.Width/Img.Height;
if(Img.Width>Img.Height)
{
Img.Width=150;Img.Height=Convert.ToInt32(Convert.ToSingle(150)/k);
}
else
{
Img.Height=150;Img.Width=Convert.ToInt32(Convert.ToSingle(150)*k);
}
或者
<img border="0" src="[!--picurl--]" onload="if(this.width>screen.width-150)this.style.width=screen.width-150; else if(this.width<screen.width-550)this.style.width=screen.width+150;">