@csstools/postcss-sign-functions
Use sign and abs functions in CSS
Last updated 4 months ago by romainmenke .
MIT-0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @csstools/postcss-sign-functions 
SYNC missed versions from official npm registry.

PostCSS Sign Functions PostCSS Logo

npm install @csstools/postcss-sign-functions --save-dev

PostCSS Sign Functions lets you use the sign and abs functions, following the CSS Values 4 specification.

.sign {
	z-index: sign(-10px);
}

.sign {
	z-index: sign(0);
}

.sign {
	z-index: sign(10px);
}

.abs {
	z-index: abs(-10px);
}

.abs {
	z-index: abs(0);
}

.abs {
	z-index: abs(10px);
}

.abs {
	z-index: abs(10%);
}

/* becomes */

.sign {
	z-index: -1;
}

.sign {
	z-index: 0;
}

.sign {
	z-index: 1;
}

.abs {
	z-index: 10px;
}

.abs {
	z-index: 0;
}

.abs {
	z-index: 10px;
}

.abs {
	z-index: max((10%), -1 * (10%));
}

[!NOTE] The utility of static fallbacks for sign and abs is limited. The most interesting values are variables and dynamic values (e.g. those containing %). It is impossible to generate static fallbacks in a build process for values that are dynamic on the client.

Usage

Add PostCSS Sign Functions to your project:

npm install postcss @csstools/postcss-sign-functions --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssSignFunctions = require('@csstools/postcss-sign-functions');

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

⚠️ About custom properties

Given the dynamic nature of custom properties it's impossible to know what the variable value is, which means the plugin can't compute a final value for the stylesheet.

Because of that, any usage that contains a var is skipped.

Options

preserve

The preserve option determines whether the original notation is preserved. By default, it is not preserved.

postcssSignFunctions({ preserve: true })
.sign {
	z-index: sign(-10px);
}

.sign {
	z-index: sign(0);
}

.sign {
	z-index: sign(10px);
}

.abs {
	z-index: abs(-10px);
}

.abs {
	z-index: abs(0);
}

.abs {
	z-index: abs(10px);
}

.abs {
	z-index: abs(10%);
}

/* becomes */

.sign {
	z-index: -1;
	z-index: sign(-10px);
}

.sign {
	z-index: 0;
	z-index: sign(0);
}

.sign {
	z-index: 1;
	z-index: sign(10px);
}

.abs {
	z-index: 10px;
	z-index: abs(-10px);
}

.abs {
	z-index: 0;
	z-index: abs(0);
}

.abs {
	z-index: 10px;
	z-index: abs(10px);
}

.abs {
	z-index: max((10%), -1 * (10%));
	z-index: abs(10%);
}

Current Tags

  • 2.0.10                                ...           latest (10 days ago)

17 Versions

  • 2.0.10                                ...           10 days ago
  • 2.0.9                                ...           2 months ago
  • 2.0.8                                ...           2 months ago
  • 2.0.7                                ...           2 months ago
  • 2.0.6                                ...           2 months ago
  • 2.0.5                                ...           3 months ago
  • 2.0.4                                ...           4 months ago
  • 2.0.3                                ...           6 months ago
  • 2.0.2                                ...           7 months ago
  • 2.0.1                                ...           9 months ago
  • 2.0.0                                ...           10 months ago
  • 1.1.4                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Total 71
Today 0
This Week 1
This Month 46
Last Day 0
Last Week 7
Last Month 24
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE