githubEdit

PostCSS Calc

NPM Versionarrow-up-right Build Statusarrow-up-right Support Chatarrow-up-right

PostCSS Calcarrow-up-right lets you reduce calc() references whenever it's possible. This can be particularly useful with the PostCSS Custom Propertiesarrow-up-right plugin.

When multiple units are mixed together in the same expression, the calc() statement is left as is, to fallback to the W3C calc() implementationarrow-up-right.

Installation

npm install postcss-calc

Usage

// dependencies
var fs = require("fs")
var postcss = require("postcss")
var calc = require("postcss-calc")

// css to be processed
var css = fs.readFileSync("input.css", "utf8")

// process css
var output = postcss()
  .use(calc())
  .process(css)
  .css

Example (with PostCSS Custom Propertiesarrow-up-right enabled as well):

Using this input.css:

you will get:

Checkout testsarrow-up-right for more examples.

Options

precision (default: 5)

Allow you to define the precision for decimal numbers.

preserve (default: false)

Allow you to preserve calc() usage in output so browsers will handle decimal precision themselves.

warnWhenCannotResolve (default: false)

Adds warnings when calc() are not reduced to a single value.

mediaQueries (default: false)

Allows calc() usage as part of media query declarations.

selectors (default: false)

Allows calc() usage as part of selectors.

Example:


Contributing

Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.

Last updated

Was this helpful?