- 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 - Clearfix
- 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 - 全部
- CSS - 內嵌
- CSS - 隔離
- CSS - 溢位滾動
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大塊級尺寸
- CSS - 最小塊級尺寸
- CSS - 混合模式
- CSS - 最大內聯尺寸
- CSS - 最小內聯尺寸
- CSS - 偏移量
- CSS - 重音色
- CSS - 使用者選擇
- 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 - justify-self 屬性
CSS justify-self 屬性透過為所有盒子專案設定預設的 justify-self 值,來提供每個盒子在相關軸上的預設對齊方式。
語法
justify-self: auto | normal | stretch | start | right | center | left | end | overflow-alignment | baseline alignment | initial | inherit;
屬性值
| 值 | 描述 |
|---|---|
| auto | 它繼承網格容器的 justify-items 屬性值。預設值。 |
| normal | 它取決於佈局模式,對於網格佈局,它與“stretch”相同。 |
| stretch | 如果未設定寬度,它會拉伸以填充網格單元格。 |
| start | 它將專案與對齊容器的內聯方向邊緣的起始位置對齊。 |
| left | 它將專案與對齊容器的左邊緣對齊。 |
| center | 它將專案與對齊容器的中心邊緣對齊。 |
| end | 它將專案與對齊容器的內聯方向邊緣的結束位置對齊。 |
| right | 它將專案與對齊容器的右邊緣對齊。 |
| 溢位對齊 |
|
| 基線對齊 | 元素與父元素的基線對齊。 |
| initial | 它將屬性設定為其預設值。 |
| inherit | 它從父元素繼承屬性。 |
CSS Justify Self 屬性示例
以下示例解釋了使用不同值的justify-self 屬性。
使用 Auto 值的 Justify Self 屬性
要讓網格專案根據網格容器的justify-items 屬性指定的預設對齊方式進行對齊,我們使用auto 值。網格專案將使用為容器設定的對齊行為。在以下示例中,justify-items 已設定為“stretch”。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.item {
justify-self: auto;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: auto
</h4>
<div class="container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Normal 值的 Justify Self 屬性
normal 值類似於auto 值,因為它通常對應於預設的對齊行為。它通常根據網格容器的預設設定對齊專案。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.item {
justify-self: normal;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: normal
</h4>
<div class="container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Stretch 值的 Justify Self 屬性
要使網格專案拉伸以填充其網格單元格的整個寬度,我們使用stretch 值。它確保專案擴充套件以適應可用空間。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.item {
justify-self: stretch;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: stretch
</h4>
<div class="container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Start 值的 Justify Self 屬性
要將網格專案與網格單元格的起始邊緣對齊,我們使用start 值。在從左到右 (LTR) 的語言中,這等效於向左對齊;在從右到左 (RTL) 的語言中,它向右對齊。direction 屬性決定起始邊緣。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.first-container {
direction: ltr;
}
.second-container {
direction: rtl;
}
.item {
justify-self: start;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: start; direction: ltr;
</h4>
<div class="first-container container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
<h4>
justify-self: start; direction: rtl;
</h4>
<div class="second-container container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 End 值的 Justify Self 屬性
將網格專案與網格單元格的結束邊緣對齊,我們使用end 值。在從左到右 (LTR) 的語言中,這等效於向右對齊;在從右到左 (RTL) 的語言中,它向左對齊。direction 屬性決定結束邊緣。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.first-container {
direction: ltr;
}
.second-container {
direction: rtl;
}
.item {
justify-self: end;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: end; direction: ltr;
</h4>
<div class="first-container container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
<h4>
justify-self: end; direction: rtl;
</h4>
<div class="second-container container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Center 值的 Justify Self 屬性
要將網格專案與網格單元格的中心對齊,我們使用center 值。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.item {
justify-self: center;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: center
</h4>
<div class="container first">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Left 值的 Justify Self 屬性
要將網格專案與網格單元格的左邊緣對齊,我們使用left 值。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.item {
justify-self: left;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: left
</h4>
<div class="container first">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Right 值的 Justify Self 屬性
要將網格專案與網格單元格的右邊緣對齊,我們使用right 值。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.item {
justify-self: right;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: right
</h4>
<div class="container first">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Last Baseline 值的 Justify Self 屬性
要將網格專案與其基線與網格單元格的最後一個基線對齊,我們使用last baseline 值。這對於對齊文字元素很有用,以便每個網格專案中的最後一行文字水平對齊。這在以下示例中顯示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 3px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightblue;
text-align: center;
border: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
.item {
justify-self: last baseline;
}
</style>
</head>
<body>
<h2>
CSS justify-self property
</h2>
<h4>
justify-self: last baseline
</h4>
<div class="container">
<div>
Item-1
</div>
<div class="item">
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
支援的瀏覽器
| 屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| justify-self | 57.0 | 16.0 | 45.0 | 10.1 | 44.0 |




