4.0.0 • Published 6 years ago

postcss-short-size v4.0.0

Weekly downloads
8,694
License
CC0-1.0
Repository
github
Last release
6 years ago

PostCSS Short Size

NPM Version Build Status Support Chat

PostCSS Short Size lets you use size properties to represent width and height in CSS, following the 1-to-2 syntax.

.image {
  size: 100px;
}

.video {
  max-size: 400px 300px;
}

/* becomes */

.image {
  width: 100px;
  height: 100px;
}

.video {
  max-width: 400px;
  max-height: 300px;
}

The supported properties are size, min-size, and max-size.

Usage

Add PostCSS Short Size to your project:

npm install postcss-short-size --save-dev

Use PostCSS Short Size to process your CSS:

const postcssShortSize = require('postcss-short-size');

postcssShortSize.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssShortSize = require('postcss-short-size');

postcss([
  postcssShortSize(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS Short Size runs in all Node environments, with special instructions for:

NodePostCSS CLIWebpackCreate React AppGulpGrunt

Options

prefix

The prefix option defines a prefix required by properties being transformed. Wrapping dashes are automatically applied, so that x would transform -x-margin.

postcssShortSize({ prefix: 'x' });
.image {
  x-size: 100px;
}

/* becomes */

.image {
  width: 100px;
  height: 100px;
}

skip

The skip option defines the skip token used to ignore portions of the shorthand.

postcssShortSize({ skip: '-' });
.image {
  size: - 100px;
}

/* becomes */

.image {
  height: 100px;
}