
- 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 物件 alignSelf 屬性
HTML DOM Style 物件**alignSelf**屬性用於設定彈性容器內專案的預設對齊方式。
語法
以下是獲取或設定 alignSelf 屬性的語法。
獲取 alignSelf 屬性object.style.alignSelf = "auto | stretch | center | flex-start | flex-end | baseline | initial | inherit";設定 alignSelf 屬性
object.style.alignSelf;
屬性值
此屬性接受以下列出的值。
值 | 描述 |
---|---|
auto | 這是預設的屬性值。在此元素繼承其父容器的 align-items 屬性,或者如果它沒有父容器,則將元素設定為“stretch”。 |
stretch | 這是預設的屬性值。它將專案拉伸以適應容器。 |
center | 它將專案定位到容器的中心。 |
flex-start | 它將專案定位在容器的開頭。 |
flex-end | 它將專案定位在容器的結尾。 |
baseline | 它將專案定位在容器的基線。 |
initial | 它用於將此屬性設定為其預設值。 |
inherit | 它用於繼承其父元素的屬性。 |
返回值
它返回一個字串值,表示元素的 align-self 屬性。
HTML DOM Style 物件“alignSelf”屬性的示例
以下示例說明了該屬性的不同值。
將值設定為 stretch 和 center
在此示例中,我們將 alignSelf 值設定為**stretch**和**center**。
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Style Object alignSelf Property</title> <style> #align { width: 300px; height: 300px; border: 1px solid #000000; display: flex; } #point { align-self: center; } </style> </head> <body> <div id="align"> <div style="background-color:rgb(158, 225, 118);">Welcome</div> <div style="background-color:rgb(119, 205, 234);">to Tutorials</div> <div style="background-color:rgb(211, 145, 219);" id="point">Point</div> </div> <p>Click button to change property.</p> <p id="id"></p> <button onclick="fun()">stretch</button> <button onclick="funtwo()">center</button> <script> function fun() { document.getElementById("point").style.alignSelf = "stretch"; } function funtwo() { document.getElementById("point").style.alignSelf = "center"; } </script> </body> </html>
將值設定為 flex-start 和 flex-end
在此示例中,我們將 alignSelf 值設定為**flex-start**和**flex-end**。
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Style Object alignSelf Property</title> <style> #align { width: 300px; height: 300px; border: 1px solid #000000; display: flex; } #point { align-self: center; } </style> </head> <body> <div id="align"> <div style="background-color:rgb(158, 225, 118);">Welcome</div> <div style="background-color:rgb(119, 205, 234);">to Tutorials</div> <div style="background-color:rgb(211, 145, 219);" id="point">Point</div> </div> <p>Click button to change property.</p> <p id="id"></p> <button onclick="fun()">flex start</button> <button onclick="funtwo()">flex end</button> <script> function fun() { document.getElementById("point").style.alignSelf = "flex-start"; } function funtwo() { document.getElementById("point").style.alignSelf = "flex-end"; } </script> </body> </html>
將值設定為 auto 和 baseline
在此示例中,我們將 alignSelf 值設定為**auto**和**baseline**。
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Style Object alignSelf Property</title> <style> #align { width: 300px; height: 300px; border: 1px solid #000000; display: flex; } #point { align-self: center; } </style> </head> <body> <div id="align"> <div style="background-color:rgb(158, 225, 118);">Welcome</div> <div style="background-color:rgb(119, 205, 234);">to Tutorials</div> <div style="background-color:rgb(211, 145, 219);" id="point">Point</div> </div> <p>Click button to change property.</p> <p id="id"></p> <button onclick="fun()">auto</button> <button onclick="funtwo()">baseline</button> <script> function fun() { document.getElementById("point").style.alignSelf = "auto"; } function funtwo() { document.getElementById("point").style.alignSelf = "baseline"; } </script> </body> </html>
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
alignSelf | 是 29 | 是 12 | 是 20 | 是 9 | 是 12.1 |
html_dom_style_object_reference.htm
廣告