- 最終更新
- 2026/08/17
3秒でわかる
CSS Gridで列数をコンテナの幅に合わせて自動で決めるキーワード。メディアクエリを書かずに折り返すカードを組めます。
30秒図解
もう少し詳しく
どういうものか
auto-fill は、CSS Gridの repeat() にminmax() と
なぜ必要か
従来はブレークポイントごとにauto-fill は
具体例
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 16px;
}幅が
コンテナ幅 900px / 最小幅 220px / アイテム3個
auto-fill [item][item][item][空 ] 空のトラックを残すのでカードは伸びない
auto-fit [ item ][ item ][ item ] 空を畳むので3個が幅いっぱいに伸びるつまずきやすいところ
auto-fill と auto-fit のauto-fill、余白をauto-fit です。1fr はminmax() の第1引数にはauto を
似た用語との違い
| 指定 | 挙動 |
|---|---|
repeat(3, 1fr) | 常に |
repeat(auto-fill, minmax(220px, 1fr)) | 収まる |
repeat(auto-fit, minmax(220px, 1fr)) | 空トラックを |

