LAYOUT / 065

Flexbox

一方向に並べる
要素を一列に並べ、空き領域を分け合います。

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

ラボで詳しく試す ↗

ひとつ試すなら

どこが変わるかを観察して、似た表現と見比べてみよう。

こんなときに

ナビゲーション、ラベル列、カード内の整列。

仕組みと使い方

折り返した各行の列幅をそろえたい場合はGridも比較します。

flex横並び整列伸縮
実装コードを見る
<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 .flex{display:flex;align-items:center;gap:9px;width:230px;height:140px}.sample i{flex:1;height:60px}.sample i:nth-child(2){flex:2;height:115px}.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="flex"><i>A</i><i>B</i><i>C</i></div>
</div>