フレックス項目
項目の伸長、収縮、簡略指定のサイズ動作を設定します。
コンテナに余りや不足があるときの flex item のサイズ挙動を指定します。flex のプリセットは basis、grow、shrink の組み合わせを選び、grow と shrink はそれぞれの比率を個別に指定します。
クラスと CSS の早見表
| クラスの例 | 期待される宣言 |
|---|---|
flex-1 | flex: 1 1 0%; |
flex-auto | flex: 1 1 auto; |
flex-initial | flex: 0 1 auto; |
flex-none | flex: none; |
grow | flex-grow: 1; |
grow-0 | flex-grow: 0; |
grow-[2] | flex-grow: 2; |
shrink | flex-shrink: 1; |
shrink-0 | flex-shrink: 0; |
shrink-[2] | flex-shrink: 2; |
basis-auto | flex-basis: auto; |
basis-1/2 | flex-basis: calc(100% * 1 / 2); |
order-first | order: -9999; |
order-last | order: 9999; |
例の設定
すべてのプレビューは spec 1、reset "none"、strict モード、spacingUnit "0.25rem"、ブレークポイントなしを明示した設定から始まります。数値の spacing はこの単位を掛けて解決し、Tailwind のテーマは継承しません。wind-demo クラスはデモ用の自作スタイルで、HTML と一緒に CSS を確認できます。
使い方の例
flex のプリセットを比較
4つのプリセットは flex-basis、flex-grow、flex-shrink の値が異なるため、行の空間を別々に分配します。
<div class="wind-demo">
<div class="wind-demo-note">Compare how each item uses its base size and available space.</div>
<div class="wind-demo-frame flex w-72 gap-2">
<div class="wind-demo-tile flex-1 w-16">flex-1</div>
<div class="wind-demo-tile flex-auto w-16">flex-auto</div>
<div class="wind-demo-tile flex-initial w-16">flex-initial</div>
<div class="wind-demo-tile flex-none w-16">flex-none</div>
</div>
</div>@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
:root {
--zw-spacing-unit: .25rem;
}
}
.wind-demo {
font: 14px / 1.45 system-ui, sans-serif;
color: #203046;
}
.wind-demo-frame {
border: 1px solid #9aaabd;
background: #f8fafc;
padding: .75rem;
}
.wind-demo-note {
color: #53677f;
font-size: .875rem;
}
.wind-demo-tile {
border: 1px solid #849bb3;
background: #dce8f2;
color: #203046;
padding: .5rem;
text-align: center;
}
.flex {
display: flex;
}
.flex-1 {
flex: 1 1 0%;
}
.flex-auto {
flex: 1 1 auto;
}
.flex-initial {
flex: 0 1 auto;
}
.flex-none {
flex: none;
}
.w-16 {
width: 4rem;
}
.w-72 {
width: 18rem;
}
.gap-2 {
column-gap: 0.5rem;
row-gap: 0.5rem;
}この例の設定
{
"wind": {
"spec": 1,
"reset": "none",
"strict": true,
"tokens": {
"spacingUnit": "0.25rem"
},
"breakpoints": {},
"defaultTransitionTimingFunction": "ease",
"authoredClasses": {
"wind-demo": true,
"wind-demo-frame": true,
"wind-demo-note": true,
"wind-demo-tile": true
},
"safelist": {
"docs-preview": [
"flex",
"flex-1",
"flex-auto",
"flex-initial",
"flex-none",
"gap-2",
"w-16",
"w-72"
]
}
}
}デモ用の自作 CSS
.wind-demo { font: 14px/1.45 system-ui, sans-serif; color: #203046; }
.wind-demo-frame { border: 1px solid #9aaabd; background: #f8fafc; padding: 0.75rem; }
.wind-demo-note { color: #53677f; font-size: 0.875rem; }
.wind-demo-tile { border: 1px solid #849bb3; background: #dce8f2; color: #203046; padding: 0.5rem; text-align: center; }余った幅を分ける
grow は比率1で広がり、grow-0 は固定項目を広げません。grow-[2] は grow の2倍の余り幅を受け取ります。
<div class="wind-demo">
<p class="wind-demo-note">Extra space is split according to grow factors.</p>
<div class="wind-demo-frame flex w-72 gap-2">
<div class="wind-demo-tile grow">grow 1</div>
<div class="wind-demo-tile grow-0 w-16">grow-0</div>
<div class="wind-demo-tile grow-[2]">grow-[2]</div>
</div>
</div>@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
:root {
--zw-spacing-unit: .25rem;
}
}
.wind-demo {
font: 14px / 1.45 system-ui, sans-serif;
color: #203046;
}
.wind-demo-frame {
border: 1px solid #9aaabd;
background: #f8fafc;
padding: .75rem;
}
.wind-demo-note {
color: #53677f;
font-size: .875rem;
}
.wind-demo-tile {
border: 1px solid #849bb3;
background: #dce8f2;
color: #203046;
padding: .5rem;
text-align: center;
}
.flex {
display: flex;
}
.grow {
flex-grow: 1;
}
.grow-0 {
flex-grow: 0;
}
.grow-\[2\] {
flex-grow: 2;
}
.w-16 {
width: 4rem;
}
.w-72 {
width: 18rem;
}
.gap-2 {
column-gap: 0.5rem;
row-gap: 0.5rem;
}この例の設定
{
"wind": {
"spec": 1,
"reset": "none",
"strict": true,
"tokens": {
"spacingUnit": "0.25rem"
},
"breakpoints": {},
"defaultTransitionTimingFunction": "ease",
"authoredClasses": {
"wind-demo": true,
"wind-demo-frame": true,
"wind-demo-note": true,
"wind-demo-tile": true
},
"safelist": {
"docs-preview": [
"flex",
"gap-2",
"grow",
"grow-0",
"grow-[2]",
"w-16",
"w-72"
]
}
}
}デモ用の自作 CSS
.wind-demo { font: 14px/1.45 system-ui, sans-serif; color: #203046; }
.wind-demo-frame { border: 1px solid #9aaabd; background: #f8fafc; padding: 0.75rem; }
.wind-demo-note { color: #53677f; font-size: 0.875rem; }
.wind-demo-tile { border: 1px solid #849bb3; background: #dce8f2; color: #203046; padding: 0.5rem; text-align: center; }縮み方を制御
shrink の項目は初期幅より縮み、shrink-0 は幅を保ちます。比率2の最後の項目は不足分をより多く引き受けます。
<div class="wind-demo">
<p class="wind-demo-note">These starting widths are wider than the row.</p>
<div class="wind-demo-frame flex w-64 gap-2">
<div class="wind-demo-tile shrink w-48">shrink</div>
<div class="wind-demo-tile shrink-0 w-48 wind-demo-alt">shrink-0 keeps its width</div>
<div class="wind-demo-tile shrink-[2] w-48">shrink-[2]</div>
</div>
</div>@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
:root {
--zw-spacing-unit: .25rem;
}
}
.wind-demo {
font: 14px / 1.45 system-ui, sans-serif;
color: #203046;
}
.wind-demo-alt {
border-color: #b39761;
background: #efe5cb;
color: #483a1d;
}
.wind-demo-frame {
border: 1px solid #9aaabd;
background: #f8fafc;
padding: .75rem;
}
.wind-demo-note {
color: #53677f;
font-size: .875rem;
}
.wind-demo-tile {
border: 1px solid #849bb3;
background: #dce8f2;
color: #203046;
padding: .5rem;
text-align: center;
}
.flex {
display: flex;
}
.shrink {
flex-shrink: 1;
}
.shrink-0 {
flex-shrink: 0;
}
.shrink-\[2\] {
flex-shrink: 2;
}
.w-48 {
width: 12rem;
}
.w-64 {
width: 16rem;
}
.gap-2 {
column-gap: 0.5rem;
row-gap: 0.5rem;
}この例の設定
{
"wind": {
"spec": 1,
"reset": "none",
"strict": true,
"tokens": {
"spacingUnit": "0.25rem"
},
"breakpoints": {},
"defaultTransitionTimingFunction": "ease",
"authoredClasses": {
"wind-demo": true,
"wind-demo-alt": true,
"wind-demo-frame": true,
"wind-demo-note": true,
"wind-demo-tile": true
},
"safelist": {
"docs-preview": [
"flex",
"gap-2",
"shrink",
"shrink-0",
"shrink-[2]",
"w-48",
"w-64"
]
}
}
}デモ用の自作 CSS
.wind-demo { font: 14px/1.45 system-ui, sans-serif; color: #203046; }
.wind-demo-alt { border-color: #b39761; background: #efe5cb; color: #483a1d; }
.wind-demo-frame { border: 1px solid #9aaabd; background: #f8fafc; padding: 0.75rem; }
.wind-demo-note { color: #53677f; font-size: 0.875rem; }
.wind-demo-tile { border: 1px solid #849bb3; background: #dce8f2; color: #203046; padding: 0.5rem; text-align: center; }basis と order
basis-and-order は対応済みの Wind ユーティリティクラスを使います。
<div class="wind-demo-new flex"><span class="basis-auto order-first">first</span><span class="basis-1/2 order-last">last</span></div>@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
:root {
--zw-spacing-unit: .25rem;
}
}
.wind-demo-new {
color: #203046;
font: 14px / 1.5 system-ui, sans-serif;
}
.flex {
display: flex;
}
.basis-1\/2 {
flex-basis: calc(100% * 1 / 2);
}
.basis-auto {
flex-basis: auto;
}
.order-first {
order: -9999;
}
.order-last {
order: 9999;
}この例の設定
{
"wind": {
"spec": 1,
"reset": "none",
"strict": true,
"tokens": {
"spacingUnit": "0.25rem"
},
"breakpoints": {},
"defaultTransitionTimingFunction": "ease",
"authoredClasses": {
"wind-demo-new": true
},
"safelist": {
"docs-preview": [
"flex",
"basis-auto",
"basis-1/2",
"order-first",
"order-last"
]
}
}
}デモ用の自作 CSS
.wind-demo-new { color: #203046; font: 14px/1.5 system-ui, sans-serif; }任意値と名前付きの値
flex-1 は 1 1 0%、flex-auto は 1 1 auto、flex-initial は 0 1 auto、flex-none は none です。grow と shrink の既定値は1で、-0 形は0です。grow-[2] のような任意の数値も使えます。比率の効果を見るには親に display:flex を設定します。
関連ガイド: ユーティリティの文法 · バリアント
カタログの詳細
flex-1
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.flex-1 |
| クラスパターン | flex-1 |
| 文法 | {"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false} |
| 受け入れる値 | 1 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | forbidden |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 0 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | flex |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
exact | null | "1 1 0%" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
flex | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
flex-1 | flex: 1 1 0% |
flex-auto
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.flex-auto |
| クラスパターン | flex-auto |
| 文法 | {"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false} |
| 受け入れる値 | 1 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | forbidden |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 0 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | flex |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
exact | null | "1 1 auto" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
flex | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
flex-auto | flex: 1 1 auto |
flex-initial
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.flex-initial |
| クラスパターン | flex-initial |
| 文法 | {"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false} |
| 受け入れる値 | 1 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | forbidden |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 0 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | flex |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
exact | null | "0 1 auto" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
flex | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
flex-initial | flex: 0 1 auto |
flex-none
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.flex-none |
| クラスパターン | flex-none |
| 文法 | {"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false} |
| 受け入れる値 | 1 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | forbidden |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 0 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | flex |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
exact | null | "none" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
flex | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
flex-none | flex: none |
grow
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.grow |
| クラスパターン | grow or grow-<suffix> |
| 文法 | {"acceptedKinds":["keyword","arbitrary"],"arbitraryProperty":"flex-grow","allowsFractionSlash":false,"allowsColorOpacity":false} |
| 受け入れる値 | 2 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | forbidden |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 0 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | flex-grow |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
keyword | null | "1" |
keyword | "0" | "0" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
flex-grow | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
grow | flex-grow: 1 |
shrink
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.shrink |
| クラスパターン | shrink or shrink-<suffix> |
| 文法 | {"acceptedKinds":["keyword","arbitrary"],"arbitraryProperty":"flex-shrink","allowsFractionSlash":false,"allowsColorOpacity":false} |
| 受け入れる値 | 2 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | forbidden |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 0 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | flex-shrink |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
keyword | null | "1" |
keyword | "0" | "0" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
flex-shrink | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
shrink | flex-shrink: 1 |
basis
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.basis |
| クラスパターン | basis-<suffix> |
| 文法 | {"acceptedKinds":["keyword","fraction"],"arbitraryProperty":null,"allowsFractionSlash":true,"allowsColorOpacity":false} |
| 受け入れる値 | 8 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | forbidden |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 1 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | flex-basis |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
keyword | "auto" | "auto" |
keyword | "full" | "100%" |
keyword | "px" | "1px" |
keyword | "0" | "0" |
keyword | "min" | "min-content" |
keyword | "max" | "max-content" |
keyword | "fit" | "fit-content" |
keyword | "content" | "content" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
flex-basis | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
basis-auto | flex-basis: auto |
order
| フィールド | 値 |
|---|---|
| カタログ識別子 | v1.order |
| クラスパターン | order-<suffix> |
| 文法 | {"acceptedKinds":["keyword","integer"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false} |
| 受け入れる値 | 3 |
| トークンカテゴリ | トークンカテゴリなし |
| 負の値の規則 | allowed |
| 競合グループと順位 | flex-item (5) |
| 並び順の順位 | 2 |
| セレクタの形 | ownElement |
| 仕様バージョン | 1 |
| 出力するプロパティ | order |
受け入れる値
| 種類 | 接尾辞 | 出力される値 |
|---|---|---|
keyword | "first" | "-9999" |
keyword | "last" | "9999" |
keyword | "none" | "0" |
宣言テンプレート
| プロパティ | 値の種類 | 固定値 |
|---|---|---|
order | resolved | null |
カタログの例
| クラスの例 | 期待される宣言 |
|---|---|
order-first | order: -9999 |