LAYOUT / 064

CSS Grid

縦横をそろえるグリッド
行と列を定義し、二方向の整列をつくります。

実際のHTML・CSSで描かれた見本です。

ラボで詳しく試す ↗

ひとつ試すなら

縦横の基準線を探す

こんなときに

カード一覧、誌面のような構成、複雑な整列。

仕組みと使い方

列の比率とgapを先に決めると、構成が整理できます。

グリッドgrid整列段組み
実装コードを見る
<style>
.sample{width:100%;height:100%;min-height:190px;display:grid;place-items:center;position:relative;overflow:hidden;box-sizing:border-box;font-family:Arial,'Hiragino Kaku Gothic ProN',Meiryo,sans-serif;color:#20211d;background:#f1f0e9;padding:22px}.sample *{box-sizing:border-box}.sample button,.sample input,.sample summary{font:inherit}.sample button,.sample summary,.sample label{touch-action:manipulation}.sample :focus-visible{outline:3px solid #6050bf;outline-offset:5px}.sample small{font-size:10px;line-height:1.5}.sample .editable{margin:0}.sample svg{max-width:100%;height:auto}
.sample .grid{width:220px;height:132px;display:grid;grid-template-columns:repeat(3,1fr);gap:8px}.sample i{font-style:normal;display:grid;place-items:center;background:var(--accent,#c9f537);border-radius:5px;font-size:16px;font-weight:700;min-width:0}.sample i:nth-child(2n){background:#b9a9e8}.sample i:nth-child(3n){background:#ff865d}
</style>
<div class="sample">
<div class="grid"><i>A</i><i>B</i><i>C</i><i>D</i><i>E</i><i>F</i></div>
</div>