Skip to content

A PostCSS plugin to fix an element's dimensions to an aspect ratio

License

Notifications You must be signed in to change notification settings

yisibl/postcss-aspect-ratio-mini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7d0c220 · Nov 25, 2021

History

10 Commits
Nov 25, 2021
Jul 12, 2017
Jul 12, 2017
Jul 12, 2017
Nov 24, 2021
Dec 3, 2018
May 13, 2020
Jul 12, 2017
May 13, 2020
Nov 25, 2021
Nov 25, 2021
Nov 24, 2021

Repository files navigation

PostCSS Aspect Ratio Mini Travis Build Status

A PostCSS plugin to fix an element's dimensions to an aspect ratio.

There is already a standard aspect-ratio in the CSS specification, and Chrome has experimental support. So it is recommended to use / to separate values, the next version may deprecate : separator.

Install

npm i postcss-aspect-ratio-mini --save

Usage

var postcss = require('postcss')

var output = postcss()
  .use(require('postcss-aspect-ratio-mini'))
  .process(require('fs').readFileSync('input.css', 'utf8'))
  .css

Example

A simple example using the custom ratio value 16 / 9.

Input

.aspect-box {
    position: relative;
}

.aspect-box {
    aspect-ratio: 16 / 9;
}

.aspect-box2 {
    aspect-ratio: 0.1 / 0.3;
}

Output

.aspect-box {
    position: relative;
}

.aspect-box:before {
    padding-top: 56.25%;
}

.aspect-box2:before {
    padding-top: 300%;
}

Test

npm test

About

A PostCSS plugin to fix an element's dimensions to an aspect ratio

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published