Skip to content

Latest commit

 

History

History
116 lines (85 loc) · 3.31 KB

File metadata and controls

116 lines (85 loc) · 3.31 KB

HTML height 属性

示例

height 属性指定元素的高度,以像素为单位。

适用于

height 属性可用于以下元素:

元素 Element 属性 Attribute
<canvas> height
<embed> height
<iframe> height
<img> height
<input> height
<object> height
<video> height

示例

Canvas 示例

一个高度和宽度为 200 像素的 <canvas> 元素:

<canvas id="myCanvas" width="200" height="200" style="border:1px solid">

Embed 示例

一个高度和宽度为 200 像素的 Flash 动画:

<embed src="helloworld.swf" width="200" height="200">

Iframe 示例

指定高度和宽度为 200 像素的 <iframe>

<iframe src="./header.html" width="200" height="200">
</iframe>

Img 示例

一个高度和宽度为 42 像素的图像:

<img src="../assets/chrome.svg" alt="Smiley face" height="42" width="42">

Input 示例

定义一个图像作为提交按钮,具有高度和宽度属性:

<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="image" src="../assets/chrome.svg" alt="Submit" width="48" height="48">
</form>

Object 示例

一个高度和宽度为 400 像素的 Flash 动画:

<object data="helloworld.swf" height="400" width="400"></object>

Video 示例

具有指定高度和宽度的视频播放器:

<video width="320" controls>
  <source
    type="video/mp4"
    src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4">
  <source
    type="video/webm"
    src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm">
  您的浏览器不支持 video 标签。
</video>

浏览器支持

height 属性对每个元素都有以下浏览器支持:

元素 Element chrome edge firefox safari opera
<canvas> 4.0 9.0 2.0 3.1 9.0
<embed> Yes Yes Yes Yes Yes
<iframe> Yes Yes Yes Yes Yes
<img> Yes Yes Yes Yes Yes
<input> 1.0 Yes 16.0 Yes 1.0
<object> Yes Yes Yes Yes Yes
<video> Yes Yes Yes Yes Yes