<flex>

Baseline 已廣泛支援

此特性已得到良好確立,可跨多種裝置和瀏覽器版本使用。自 2017 年 3 月起,所有瀏覽器均支援此特性。

<flex> CSS 資料型別表示網格容器中的彈性長度。它用於 grid-template-columnsgrid-template-rows 和其他相關屬性。

語法

<flex> 資料型別被指定為 <number> 後跟單位 frfr 單位表示網格容器中剩餘空間的比例。與所有 CSS 尺寸一樣,單位和數字之間沒有空格。

示例

fr 資料型別的正確值示例

1fr    /* Using an integer value */
2.5fr  /* Using a float value */

在 CSS 網格佈局的軌道列表中使用的示例

css
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 2.5fr 1.5fr;
}

規範

規範
CSS 網格佈局模組 Level 2
# fr-單位

瀏覽器相容性

另見