supple-css

Supple CSS | objects.aspect-ratio

For use with multi-media embeds such as videos, images or slideshows, that need to retain a specific aspect ratio but adapt to elements of variable widths.

Read more about Supple CSS.

Table of contents

Features

Use

By default the aspect ratio container has a ratio of 1:1, a perfect square.

Note .o-aspect-ratio only accepts .o-aspect-ratio__item as direct descendant.

<div class="o-aspect-ratio">
  <iframe src=""></iframe>
</div>

Modifiers on .o-aspect-ratio

<div
  class="o-aspect-ratio [o-aspect-ratio--4by3  |  o-aspect-ratio--16by9  |  o-aspect-ratio--2by1]"
>
  <iframe src=""></iframe>
</div>

Custom properties

<div class="o-aspect-ratio" style="--aspect-ratio: (560/315);">
  <img src="" />
</div>

Note Of course this specific use of custom properties(through inline styles) is pure for example purposes. It is advised to overwrite the custom properties in your own components instead of inline styles.

Available classes

On the .o-aspect-ratio block

Configurable variables

There are multiple ways to configure the aspect-ratio object. The Custom properties are calculated at run-time, the SCSS variables will allow you to change things at build-time.

Custom properties

On the .o-aspect-ratio block

SCSS variables

You can overwrite the SCSS variables the following ways:

// in your manifest file, eg. `styles.scss`
@use 'node_modules/@supple-kit/supple-css/objects/aspect-ratio' with (
  $ratios: (
    (4: 3),
    (16: 9),
  )
);

or

// in your own variable file, eg. `_vars.scss`
@use 'node_modules/@supple-kit/supple-css/objects/aspect-ratio/variables' with (
  $ratios: (
    (4: 3),
    (16: 9),
  )
);

// in your manifest file, eg. `styles.scss`
@use 'node_modules/@supple-kit/supple-css/objects/aspect-ratio';

Installation

Make sure you’ve installed/downloaded the Supple CSS library: Supple CSS installation

Testing

Basic visual tests are in test.html.

Browser support