Image height 属性
定义和用法
height属性设置或返回图像的height属性值。
height 属性指定图像的高度。
此属性还可以返回已使用 CSS 设置样式的图像的高度(查看更多示例)。
提示:使用 width 属性设置或返回图像的宽度属性值。
浏览器支持
| 属性 | |||||
|---|---|---|---|---|---|
| height | Yes | Yes | Yes | Yes | Yes |
语法
返回 height 属性:
imageObject.height
设置 height 属性:
imageObject.height = pixels
属性值
| 值 | 描述 |
|---|---|
| pixels | 以像素为单位的高度(例如 height="100") |
技术细节
| 返回值: | 一个数字,表示图像的高度,单位为像素 |
|---|
更多实例
实例
将图像的高度和宽度更改为 300px:
document.getElementById("myImg").height = "300";
document.getElementById("myImg").width = "300";亲自试一试 »相关页面
HTML 参考手册: HTML<img> height 属性
