Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

postcss-proportional-spacing

mindthetic12CC0-1.01.0.2

Apply proportional horizontal and vertical spacing with ratios using a unitless quantity.

postcss, css, postcss-plugin, padding, margin, spacing, ratios, proportional

readme

PostCSS Proportional Spacing PostCSS

NPM Version Build Status Support Chat

Create vertical and horizontal proportional spacing using ratios.

.example {
  padding: 80px 0.5;
  margin-right: 80px;
  margin-bottom: 2;
}

Outputs:

.example {
  padding: 80px 40px;
  margin-right: 80px;
  margin-bottom: 160px;
}

When a ratio is used the value is calculated by multiplying against the adjacent sides. The respective top and right sides are checked first, and if no value is set then the respective bottom and left sides are checked.

Please let me know if you think this is not useful or if you have another suggestion as there may be a better way to manage the logic behind this that I haven't thought of.

Using with variables

You may consider using it with sass variables or custom values.

SASS Variables

https://github.com/jonathantneal/postcss-advanced-variables

$ratio-octave: 0.5;

.button {
  padding: 40px $ratio-octave;
}

Custom Values

https://github.com/mindthetic/postcss-custom-values

@value OCTAVE property(padding) {
  value: 1.5;
}

.button {
  padding: 40px OCTAVE;
}

Setup

Add to your project:

npm install postcss-proportional-spacing --save-dev

changelog

Changes to PostCSS Proportional Spacing

1.0.0 (October 1, 2018)

  • Initial version