MEDIA / 106

Aspect ratio

映像の縦横比
幅に対する高さの比率を決め、表示領域の形を保ちます。

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

ラボで詳しく試す ↗

ひとつ試すなら

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

こんなときに

動画枠、サムネイル、正方形の画像。

仕組みと使い方

実際の動画とは別に、枠の縦横比を指定できます。

アスペクト比動画16:9aspect-ratio
実装コードを見る
<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 .frame{width:225px;aspect-ratio:16/9;background:#292b25;display:flex;flex-direction:column;align-items:center;justify-content:center;color:#c9f537;border-radius:7px;gap:9px}.sample span{font:700 35px monospace}.sample small{color:#dbded2}
</style>
<div class="sample">
<div class="frame"><span>16 / 9</span><small>映像枠のサンプル</small></div>
</div>