aspect-ratio.css features lot of common ratios in both orientations:
Some of the included ratios are special and therefore got/need special names:
The library is simply used by applying the base class .ar
in combination with a ratio class .ar-[width]-[height]
.
If you plan to insert content, you need to add .ar-content
inside.
<div class="ar ar-1-1"></div>
<div class="ar ar-16-9">
<div class="ar-content">16:9</div>
</div>
Just switch the numbers respectively add -v
to the ratio class.
<div class="ar ar-9-16">
<div class="ar-content">9:16</div>
</div>
<div class="ar ar-golden-v">
<div class="ar-content">Golden ratio vertical</div>
</div>
Insert an additional element with the class .ar-center
.
1:1
Vertical
centered
content
16:9
<div class="ar ar-16-9">
<div class="ar-content">
<div class="ar-center">
<p>16:9</p>
</div>
</div>
</div>
May cause unexpected results. Make sure you handle the nested elements width properly.
2:1
1:1
1:1
1:1
<div class="ar ar-2-1">
<div class="ar-content">
2:1
<!-- row + columns -->
<div class="ar ar-1-1">
<div class="ar-content">
1:1
<!-- row + columns -->
<div class="ar ar-16-9">
<div class="ar-content">16:9</div>
</div>
</div>
</div>
</div>
</div>