Description
Produces ratio boxes, which can be optionally grow if the content is longer than the height and can also be set to be free ratio if the ratio is no longer required.
NB: You may want to use
Tailwind's official plugin. The main difference with this plugin is the ability to have
expandable ratio boxes, so effectively a
min-height
of a ratio which expands if the content is too tall.
A note about Tailwind 3's native aspect ratio
In Tailwind 3, Tailwind introduced "Modern aspect ratio API" to use browser native aspect-ratio
and so the life span of
this plugin is very much limited.
At A17 we generally try and target current major and 2 previous major versions the browsers with our styling and browser native aspect ratio isn't there just yet. As of December 2021, Safari is lagging behind. Now this might not be as big of deal as it might have been in the olden days, as iOS and MacOS is pretty good at making its users update their devices, so you'll need to weigh up how you do aspect ratio boxes in project yourself.
Browser native aspect-ratio
boxes will expand if the content is
taller than the box, unless you lock it with
min-height: 0
/min-h-0
.
Setup
Demo
Using this plugin requires a wrapper and a child.
-
The wrapper gets the ratio classes: eg:
ratio ratio-1x1
, - the child gets a class of
ratio-content
.
Based on the reference config mentioned in this guide, a 1:1 box that
changes to 16:9 ratio at the md
breakpoint:
A 16:9 box, which can grow if the content is taller than the box
(effectively this box is min-height: 16:9
):
A 16:9 ratio box that becomes free ratio at lg
.
NB:
currently not possible to make this box constrained by a ratio again at a
larger breakpoint - so
ratio-16x9 lg:ratio-free xl:ratio-16:9
would have unexpexted
results.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ligula risus, fermentum id elit sit amet, fringilla viverra metus.