
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 內聯塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - 清除浮動
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 位置
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 平移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 覆蓋層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS 高階
- CSS - 網格佈局
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 圖層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - Important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多重背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - 游標顏色
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 提示框
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特異性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - place-self 屬性
CSS place-self 是一個簡寫屬性,它同時在塊級和內聯方向上對齊單個專案,類似於網格或 Flexbox 等佈局系統中的 align-self 和 justify-self 屬性。如果沒有設定第二個值,則使用第一個值。
此屬性是以下 CSS 屬性的簡寫
可能的值
auto − 根據父元素的 align-self 值對齊專案。
normal− 基於佈局模式,normal 關鍵詞的效果會發生變化
當佈局為絕對定位時,在替換的絕對定位框中表現為start,在所有其他絕對定位框中表現為stretch。
在絕對定位佈局的靜態位置中表現為stretch。
對於彈性專案,表現為stretch。
對於網格專案,表現類似於stretch,除了具有縱橫比或內在尺寸的框,在這些框中表現為start。
不適用於塊級框和表格單元格。
self-start− 專案在交叉軸上對齊到對應於專案起始側的對齊容器的邊緣。
self-end − 專案在交叉軸上對齊到對應於專案結束側的對齊容器的邊緣。
flex-start − 將彈性專案的交叉起始邊距邊緣與行的交叉起始邊緣對齊。
flex-end− 將彈性專案的交叉結束邊距邊緣與行的交叉結束邊緣對齊。
center− 彈性專案框的邊距在交叉軸上的行內居中。當元素的交叉尺寸大於容器時,內容在兩個方向上溢位相同。
baseline, first baseline, last baseline −
first baseline 和 last baseline 是 baseline 的同義詞。First 和 last 指的是彈性專案內的行框。
這些值指定在內容對齊中是否涉及首行基線或末行基線對齊。
start 是 first-baseline 的回退對齊方式,end 是 last-baseline 的回退對齊方式。
stretch − 當專案連同交叉軸的組合尺寸小於容器尺寸,並且專案大小為auto時,其尺寸會等比例增加,同時保持max-height / max-width的值。
應用於
塊級框、絕對定位框和網格專案。
語法
關鍵字值
place-self: auto center; place-self: normal start;
位置對齊
place-self: center normal; place-self: start auto; place-self: end normal; place-self: self-start auto; place-self: self-end normal; place-self: flex-start auto; place-self: flex-end normal;
基線對齊
place-self: baseline normal; place-self: first baseline auto; place-self: last baseline normal; place-self: stretch auto;
CSS place-self - normal start 值
以下示例演示了place-self: normal start 屬性將專案 2 對齊到其網格單元格的起始位置 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: normal start; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - auto center 值
以下示例演示了place-self: auto center 屬性將專案 2 對齊到其網格單元格的中心位置 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: auto center; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - center normal 值
以下示例演示了place-self: center normal 屬性將專案 2 水平居中和垂直居中在其網格單元格中 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: center normal; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - end normal 值
以下示例演示了place-self: end normal 屬性將專案 2 水平對齊到其網格單元格的右邊緣,並垂直對齊到其網格單元格的頂部邊緣 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: end normal; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - start auto 值
以下示例演示了place-self: start auto 屬性將專案 2 對齊到其網格單元格的起始位置 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: start auto; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - self-start auto 值
以下示例演示了place-self: self-start auto 屬性將專案 2 垂直定位在行的起始位置,並在水平方向上自動定位 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: self-start auto; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - self-end normal 值
以下示例演示了place-self: self-end normal 屬性將專案 2 垂直對齊到底部,並水平對齊到其網格單元格的起始位置 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: self-end normal; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - flex-start auto 值
以下示例演示了place-self: flex-start auto 屬性將專案 2 垂直對齊到左邊緣,並水平對齊到其網格單元格的頂部 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: flex-start auto; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - flex-end normal 值
以下示例演示了place-self: flex-end normal 屬性將專案 2 對齊到其網格單元格的右邊緣 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: flex-end normal; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - baseline normal 值
以下示例演示了place-self: baseline normal 屬性將專案 2 對齊到其網格單元格的基線 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: baseline normal; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - last baseline normal 值
以下示例演示了place-self: last baseline normal 屬性將專案 2 對齊到其網格單元格的最後一行基線 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; height: 50px; } .item2 { place-self: last baseline normal; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>
CSS place-self - stretch auto 值
以下示例演示了place-self: stretch auto 屬性水平拉伸專案 2 以填充其網格單元格中的可用空間 -
<html> <head> <style> .container { background-color: red; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 100px; grid-gap: 10px; margin: 20px; width: 300px; } .container > div { background-color: greenyellow; border: 3px solid blue; text-align: center; margin: 5px; width: 60px; min-height: 50px; } .item2 { place-self: stretch auto; } </style> </head> <body> <div class="container"> <div>Item 1</div> <div class="item2">Item 2</div> <div>Item 3</div> <div>Item 4</div> </div> </body> </html>