- 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 - All
- CSS - 內嵌
- CSS - 隔離
- CSS - 溢位滾動
- 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 - 偏移量
- 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 - justify-items 屬性
CSS justify-items 屬性用於沿內聯方向(水平方向)對齊網格專案在其網格區域內的排列。它控制專案在其網格單元格內的放置方式,有效地設定它們在容器網格內的對齊方式。
語法
justify-items: legacy | normal | stretch | start | left | center | end | right | overflow-alignment | baseline alignment | initial | inherit;
屬性值
| 值 | 描述 |
|---|---|
| legacy | 此值由子盒繼承。但是,如果子代具有 justify-self: auto,則只考慮 left、right 或 center 值,而不考慮 legacy 關鍵字。預設值。 |
| normal | 它取決於佈局模式,對於網格佈局,它與“stretch”相同。 |
| stretch | 如果未設定寬度,則它會拉伸以填充網格單元格。 |
| start | 它將專案沿內聯方向對齊到對齊容器的起始邊緣。 |
| left | 它將專案沿內聯方向對齊到對齊容器的左邊緣。 |
| center | 它將專案沿內聯方向對齊到對齊容器的中心邊緣。 |
| end | 它將專案沿內聯方向對齊到對齊容器的結束邊緣。 |
| right | 它將專案沿內聯方向對齊到對齊容器的右邊緣。 |
| 溢位對齊 |
|
| 基線對齊 | 元素與父元素的基線對齊。 |
| initial | 它將屬性設定為其預設值。 |
| inherit | 它從父元素繼承屬性。 |
CSS Justify Items 屬性示例
以下示例說明了具有不同值的justify-items 屬性。
使用 Normal 值的 Justify Items 屬性
要使用預設對齊行為(在大多數現代瀏覽器中通常對應於stretch)對齊專案,我們使用normal值。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: normal;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: normal
</h4>
<div class="container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Stretch 值的 Justify Items 屬性
要讓網格專案拉伸以填充其網格單元格的整個寬度,我們使用stretch值。這是預設值。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: stretch;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: stretch
</h4>
<div class="container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Start 值的 Justify Items 屬性
要將網格專案對齊到其網格區域的起始邊緣,我們使用start值。在從左到右 (LTR) 的語言中,這等效於 left;在從右到左 (RTL) 的語言中,它對齊到右邊緣。direction 屬性確定起始邊緣。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: start;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.first{
direction: ltr;
}
.second{
direction: rtl;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: start; direction: ltr;
</h4>
<div class="container first">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
<h4>
justify-items: start; direction: rtl;
</h4>
<div class="container second">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 End 值的 Justify Items 屬性
要將網格專案對齊到其網格區域的結束邊緣,我們使用end值。在 LTR 語言中,這等效於 right;在 RTL 語言中,它對齊到左邊緣。direction 屬性確定結束邊緣。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: end;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.first {
direction: ltr;
}
.second {
direction: rtl;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: end; direction: ltr
</h4>
<div class="container first">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
<h4>
justify-items: end; direction: rtl
</h4>
<div class="container second">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Center 值的 Justify Items 屬性
要將網格專案沿內聯方向對齊到其網格區域的中心,我們使用center值。所有網格專案都在其網格單元格內水平居中對齊。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: center;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: center
</h4>
<div class="container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Left 值的 Justify Items 屬性
要將網格專案沿內聯方向對齊到其網格區域的左邊緣,我們使用left值。所有網格專案都與其各自網格單元格的左側齊平。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: left;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: left
</h4>
<div class="container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Right 值的 Justify Items 屬性
要將網格專案沿內聯方向對齊到其網格區域的右邊緣,我們使用right值。所有網格專案都與其各自網格單元格的右側齊平。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: right;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: right
</h4>
<div class="container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Baseline 值的 Justify Items 屬性
要將網格專案沿網格單元格的基線對齊,我們使用baseline值。這對於使用特定基線對齊專案很有用。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: baseline;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: baseline
</h4>
<div class="container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
使用 Legacy Right 值的 Justify Items 屬性
此值確保專案根據 CSS 網格規範完全標準化之前瀏覽器實現的行為對齊到其網格單元格的右邊緣。它旨在提供與使用不同對齊系統的舊版瀏覽器行為的向後相容性。以下示例顯示了這一點。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: legacy right;
gap: 10px;
border: 2px solid black;
height: 150px;
padding: 5px;
}
.container>div {
background-color: lightgreen;
text-align: center;
bordeR: 2px solid green;
color: white;
padding: 15px;
height: 50px;
}
</style>
</head>
<body>
<h2>
CSS justify-items property
</h2>
<h4>
justify-items: legacy right
</h4>
<div class="container">
<div>
Item-1
</div>
<div>
Item-2
</div>
<div>
Item-3
</div>
</div>
</body>
</html>
支援的瀏覽器
| 屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| justify-items | 57.0 | 16.0 | 45.0 | 10.1 | 44.0 |




