In web pages, sometimes the referenced image is too large, so that only a part of the image can be displayed. To scale the image, follow these steps:
1. Use css to control the image size:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> test </title>
<Style type = "text/css">
Img {
Border: 0;
Margin: 0;
Padding: 0; www.2cto.com
Max-width: 1280px;
Width: expression (this. width & gt; 1280? "1280px": this. width );
Max-height: 720px;
Height: expression (this. height> 720? "720px": this. height );
}
</Style>
</Head>
<Body>
<Div>
</Div>
</Body>
</Html>
Alternatively, you can use the following methods:
[Html]
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> test </title>
</Head>
<Body>
<Div style = "width: 200px; height: 100px;">
</Div>
</Body>
</Html>
The two methods are scaled proportionally according to the original image size.
2. Use js to implement:
[Html]
<Body>
<Div id = article> </div>
<Script type = "text/javascript">
// Scale the image to a proper size
Function ResizeImages ()
{
Var myimg, oldwidth, oldheight;
Var maxwidth = 1280;
Var maxheight = 720;
Var imgs = document. getElementById ('Article'). getElementsByTagName ('img '); // if your defined id is not article, modify it here
For (I = 0; I Myimg = imgs [I];
If (myimg. width> myimg. height)
{
If (myimg. width> maxwidth)
{
Oldwidth = myimg. width;
Myimg. height = myimg. height * (maxwidth/oldwidth );
Myimg. width = maxwidth;
}
} Else {
If (myimg. height> maxheight)
{
Oldheight = myimg. height;
Myimg. width = myimg. width * (maxheight/oldheight );
Myimg. height = maxheight;
}
}
}
}
// Scale the image to a proper size
ResizeImages ();
</Script>
</Body>
In this way, you can set the width and height of the image.