Sets or retrieves the calculated width of the object.
dhtml语法
HTML | <ELEMENT WIDTH
= iWidth... >
|
---|
Scripting | object.width [ = iWidth ] |
---|
DHTML可能的值
iWidth | Integer that
specifies or receives one of the following values.width | Integer that specifies the width of the object in pixels or as a percentage. | percentage | String that specifies an integer value followed by a %. The value is a percentage of the width of the parent object. |
|
The property is read/write.
The property has no default value.
Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see about dynamic properties.
remarks
if you specify the width property of an img, but not the height property, the resulting height of the img is sized proportionally to the specified width property and the actual height, in pixels, of the source image file. consider the following example:
dimensions of image in source file (pixels): | 100 x 50 (w x h) |
specified image width: | 2in |
specified image height: | not specified |
resulting image width: | 2in |
resulting image height: | 1in ((50/100) * 2 inches) |
if you specify the width property of an img, and the height and width of the image in the source file are identical, the height of the image matches the width.
if you specify the height property and the width property of an img, the resulting image dimensions match the height and width specified.
when scripting the height property, use either the pixelheight or posheight property to numerically manipulate the height value.
if dynamic changes are intended for the height and width, the original values should be set through style (e.g. "style=''height:200px; width:200px'') rather than through the height and width attributes.
although you can specify the width as a percentage, this property always retrieves the width in pixels.
DHTML代码范例
This example sets the width of the image to 20 pixels regardless of the original size of the image.
<IMG SRC="large.gif" WIDTH="20">
是否符合公共标准
This property is defined in
HTML 4.0 and
is defined in
World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 .
Applies To