
- 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 - DOM Style 物件 justifyContent 屬性
HTML DOM Style 物件 **justifyContent** 屬性設定或返回彈性專案在主軸或水平方向上的對齊方式,當它們沒有使用所有可用空間時。
語法
設定 justifyContent 屬性object.style.justifyContent= "flex-start | flex-end | center | space-between | space-around | initial | inherit";獲取 justifyContent 屬性
object.style.justifyContent;
屬性值
值 | 描述 |
---|---|
flex-start | 這是預設值,它將彈性專案對齊到容器的開頭。 |
flex-end | 它將彈性專案對齊到容器的末尾。 |
center | 它將彈性專案對齊到容器的中心。 |
space-between | 它在行之間放置彈性專案。 |
space-around | 它在行之前、之間和之後放置彈性專案。 |
initial | 用於將此屬性設定為其預設值。 |
inherit | 用於繼承其父元素的屬性。 |
返回值
它返回一個字串值,表示元素的 justify content 屬性。
HTML DOM Style 物件“justifyContent”屬性的示例
以下示例說明了應用於 div 元素的 justifyContent 屬性,該元素具有五個不同顏色的專案。
將彈性專案設定為“flex-start”和“flex-end”
在此示例中,我們將彈性容器的專案對齊到 flex-start、flex-end 和 center。
<!DOCTYPE html> <html lang="en"> <head> <style> #flex { width: 700px; height: 300px; border: 1px solid black; display: flex; } #flex div { height: 80px; width: 80px; } </style> <title> HTML DOM Style Object justifyContent Property </title> </head> <body> <p> Click to try different justifyContent property. </p> <button onclick="funTwo()">Flex-End</button> <button onclick="fun()">Flex-Start</button> <button onclick="funThree()">Center</button> <br> <br> <div id="flex"> <div style="background-color: #04af2f;">1</div> <div style="background-color: aqua;">2</div> <div style="background-color: yellow;">3</div> <div style="background-color: whitesmoke">4</div> <div style="background-color: black;">5</div> </div> <script> function funTwo() { document.getElementById("flex") .style.justifyContent = "flex-end"; } function fun() { document.getElementById("flex") .style.justifyContent = "flex-start"; } function funThree() { document.getElementById("flex") .style.justifyContent = "center"; } </script> </body> </html>
將彈性專案設定為“space-between”和“space-around”
在此示例中,我們將彈性容器的專案對齊到 space-between 和 space-around。
<!DOCTYPE html> <html lang="en"> <head> <style> #flex { width: 700px; height: 300px; border: 1px solid black; display: flex; } #flex div { height: 80px; width: 80px; } </style> <title> HTML DOM Style Object justifyContent Property </title> </head> <body> <p> Click to try different justifyContent property. </p> <button onclick="funTwo()">Space-Between</button> <button onclick="fun()">Space-Around</button> <br> <br> <div id="flex"> <div style="background-color: #04af2f;">1</div> <div style="background-color: aqua;">2</div> <div style="background-color: yellow;">3</div> <div style="background-color: whitesmoke">4</div> <div style="background-color: black;">5</div> </div> <script> function funTwo() { document.getElementById("flex") .style.justifyContent = "space-between"; } function fun() { document.getElementById("flex") .style.justifyContent = "space-around"; } </script> </body> </html>
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
justifyContent | 是 29 | 是 12 | 是 20 | 是 9 | 是 12.1 |
html_dom_style_object_reference.htm
廣告