Skip to content

supermonkeyz/postcss-aspect-ratio-property

Repository files navigation

PostCSS Aspect Ratio Property Build Status circleci

PostCSS plugin The CSS Working Group have designed an aspect-ratio property for CSS.This plugin make this future feature available now..

.foo {
    /* Input example */
    aspect-ratio: 16/9;
}
.foo {
  /* Output example */
  position: relative;
}

.foo::before {
  content: '';
  display: block;
  padding-top: 56.25%;
}

.foo > div {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

options

Type: Object

default:

{
  mainSelector: '.box'
}
.foo {
    /* Input example */
    aspect-ratio: 16/9;
}

...

.foo > .box {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

Usage

Step 1: Install plugin:

npm install --save-dev postcss postcss-aspect-ratio-property

Step 2: Check you project for existed PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Step 3: Add the plugin to plugins list:

module.exports = {
  plugins: [
+   require('postcss-aspect-ratio-property'),
    require('autoprefixer')
  ]
}

About

Postcss plugin make the aspect-ratio property available now

Resources

License

Stars

Watchers

Forks

Packages

No packages published