- HTML 教程
- HTML - 首頁
- HTML - 路線圖
- HTML - 簡介
- HTML - 歷史與演變
- HTML - 編輯器
- HTML - 基本標籤
- HTML - 元素
- HTML - 屬性
- HTML - 標題
- HTML - 段落
- HTML - 字型
- HTML - 塊
- HTML - 樣式表
- HTML - 格式化
- HTML - 引用
- HTML - 註釋
- HTML - 顏色
- HTML - 影像
- HTML - 影像地圖
- HTML - Iframes
- HTML - 短語元素
- HTML - 元標籤
- HTML - 類
- HTML - ID
- HTML - 背景
- HTML 表格
- HTML - 表格
- HTML - 表格頭和標題
- HTML - 表格樣式
- HTML - 表格 Colgroup
- HTML - 巢狀表格
- HTML 列表
- HTML - 列表
- HTML - 無序列表
- HTML - 有序列表
- HTML - 定義列表
- HTML 連結
- HTML - 文字連結
- HTML - 影像連結
- HTML - 郵件連結
- HTML 顏色名稱和值
- HTML - 顏色名稱
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML 表單
- HTML - 表單
- HTML - 表單屬性
- HTML - 表單控制元件
- HTML - 輸入屬性
- HTML 媒體
- HTML - 影片元素
- HTML - 音訊元素
- HTML - 嵌入多媒體
- HTML 頭部
- HTML - Head 元素
- HTML - 新增 Favicon
- HTML - Javascript
- HTML 佈局
- HTML - 佈局
- HTML - 佈局元素
- HTML - 使用 CSS 進行佈局
- HTML - 響應式
- HTML - 符號
- HTML - 表情符號
- HTML - 樣式指南
- HTML 圖形
- HTML - SVG
- HTML - Canvas
- HTML API
- HTML - Geolocation API
- HTML - 拖放 API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web 儲存
- HTML - 伺服器傳送事件
- HTML 雜項
- HTML - 文件物件模型 (DOM)
- HTML - MathML
- HTML - 微資料
- HTML - IndexedDB
- HTML - Web 訊息傳遞
- HTML - Web CORS
- HTML - Web RTC
- HTML 演示
- HTML - 音訊播放器
- HTML - 影片播放器
- HTML - 網頁幻燈片
- HTML 工具
- HTML - Velocity Draw
- HTML - 二維碼
- HTML - Modernizer
- HTML - 驗證
- HTML - 顏色拾取器
- HTML 參考
- HTML - 速查表
- HTML - 標籤參考
- HTML - 屬性參考
- HTML - 事件參考
- HTML - 字型參考
- HTML - ASCII 碼
- ASCII 表格查詢
- HTML - 顏色名稱
- HTML - 實體
- MIME 媒體型別
- HTML - URL 編碼
- 語言 ISO 程式碼
- HTML - 字元編碼
- HTML - 已棄用標籤
- HTML 資源
- HTML - 快速指南
- HTML - 有用資源
- HTML - 顏色程式碼生成器
- HTML - 線上編輯器
HTML - height 屬性
HTML 的 **height** 屬性用於指定元素的垂直尺寸。我們也可以使用 **height** 作為 CSS 中的屬性來指定元素的高度。
此屬性對於保持元素的縱橫比和確保設計一致性至關重要。透過管理內容中專案的視覺化呈現,Web 開發人員可以控制高度屬性以建立畫素完美的佈局並改善使用者體驗。
語法
<tag height = 'value'></tag>
任何 CSS 測量值都將被接受為 height 屬性值。
應用於
以下列出的元素允許使用 HTML height 屬性
| 元素 | 描述 |
|---|---|
| <img> | HTML <img> 標籤用於在網頁中渲染影像。 |
| <canvas> | HTML <canvas> 用於使用 JavaScript 繪製圖形。 |
| <embed> | HTML <embed> 標籤用作外部應用程式和多媒體的容器。 |
| <iframe> | HTML <iframe> 是一個內聯框架,允許我們在當前 HTML 文件中嵌入另一個文件。 |
| <input> | HTML <input> 用於接受使用者提供的各種型別的輸入。 |
| <object> | HTML <object> 標籤用於在網頁上顯示多媒體,包括音訊、影片、圖片、網站、PDF 和 Flash。 |
| <video> | HTML <video> 用於在網頁中渲染影片 |
HTML height 屬性示例
以下示例將說明 HTML height 屬性,以及我們應該在哪裡以及如何使用此屬性!
設定影像元素的高度
所有影像都有其自身的高度,但我們可以根據需要使用 HTML height 屬性設定高度。在此示例中,我們將使用 px(畫素)單位設定影像高度。您可以使用任何適合您的測量單位。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'height' attribute</title>
</head>
<body>
<h3>
Example of the HTML 'height' Attribute
</h3>
<p>
Here you can see the same image with different height value,
as we did not set the width attribute so the width is adujusted
based on height of the image.
</p>
<!--HTML 'height' attribute-->
<strong>Image with 50px height</strong>
<br>
<img src="html/images/html-mini-logo.jpg" height="50px">
<br>
<strong>Image with 100px height</strong>
<br>
<img src="html/images/html-mini-logo.jpg" height="100px">
</body>
</html>
設定輸入元素的高度
在以下示例程式碼中,我們將使用 input 標籤渲染影像並在輸入元素中設定影像的高度。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'height' attribute</title>
</head>
<body>
<h3>Example of the HTML 'height' Attribute</h3>
<p>
In this example we set the width also so
the image can render on fixed dimension 350*100(w*h).
</p>
<!--HTML 'height' attribute-->
<strong>Image with 100px height</strong>
<br>
<input type="image" src="/html/images/html-mini-logo.jpg"
height="100px" width="350px">
</body>
</html>
設定物件元素的高度
讓我們看看以下示例,我們將在此示例中對 object 元素使用 height 屬性。我們建立了一個影像物件來測試 object 元素上的 height 屬性。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'height' Attribute</title>
</head>
<body>
<h3>Example of the HTML 'height' Attribute</h3>
<p>
Here we did not mention any unit but you
can as per the need, without the unit it
measure in px(pixels).
</p>
<!--HTML 'height' attribute-->
<strong>Object with 300 height</strong>
<br>
<object data=
"https://www.plus2net.com/php_tutorial/images/pdf-student-table.PNG"
height="300">
</object>
</body>
</html>
設定 canvas 元素的高度
在此示例中,我們正在建立一個 canvas 並使用 HTML height 屬性為 canvas 元素設定高度。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'height' Attribute</title>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<h3>Example of the HTML 'height' Attribute</h3>
<p>
We have created a canvas 400*200 and using
JavaScript to fill the color by mentioning the coords
</p>
<!--HTML 'height' attribute-->
<canvas id="myCanvas" width="400" height="200">
</canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(30, 50, 335, 100);
</script>
</body>
</html>
設定 iframe 元素的高度
在這裡,我們使用 height 屬性設定 iframe 元素的高度並渲染 HTML 教程的登入頁面。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'height' Attribute</title>
</head>
<body>
<h3>Example of the HTML 'height' Attribute</h3>
<p>
We have created an iframe 400*400 and
rendering HTML landing page
</p>
<!--HTML 'height' attribute-->
<iframe src="/html/index.htm" width="450" height="400">
</body>
</html>
設定嵌入元素的高度
在此示例中,我們將嵌入我們的 HTML 教程登入頁面,並將使用 height 屬性調整嵌入元素的高度
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'height' Attribute</title>
</head>
<body>
<h3>Example of the HTML 'height' Attribute</h3>
<p>
We have embedded an image and
rendering the image in 300*100
</p>
<!--HTML 'height' attribute-->
<embed type="image/jpg" src="html/images/html.jpg"
width="300" height="100">
</body>
</html>
設定影片元素的高度
在此示例中,我們包含了一個影片並使用 height 屬性設定了影片元素的高度。由於連結損壞或訪問問題,影片可能無法播放。
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'height' Attribute</title>
</head>
<body>
<h3>Example of the HTML 'height' Attribute</h3>
<p>
We have included a video and
rendering the video in 320*240
</p>
<!--HTML 'height' attribute-->
<video width="320" height="240" controls>
<source src=
"https://cdn.pixabay.com/vimeo/165221419/ipad-2988.mp4?width=640&hash=4816e81143efa7f31f1e8c86c5605f43fdfac941"
type="video/mp4">
</body>
</html>
支援的瀏覽器
| 屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| height | 是 | 是 | 是 | 是 | 是 |
html_attributes_reference.htm
廣告




