postcss-rem
PostCSS plugin to use rem units with optional pixel fallback.
Last updated 3 years ago by pierreburel .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install postcss-rem 
SYNC missed versions from official npm registry.

postcss-rem Node.js CI

PostCSS plugin to use rem units with optional pixel fallback. Based on sass-rem.

See also: startijenn-rem, vanilla JavaScript version.

Example

Input

.demo {
  font-size: rem(24px); /* Simple */
  padding: rem(5px 10px); /* Multiple values */
  margin: rem(10px 0.5rem); /* Existing rem */
  border-bottom: rem(1px solid black); /* Multiple mixed values */
  box-shadow: rem(
    0 0 2px #ccc,
    inset 0 0 5px #eee
  ); /* Comma-separated values */
  text-shadow: rem(1px 1px) #eee, rem(-1px) 0 #eee; /* Alternate use */
}

Output

.demo {
  font-size: 1.5rem; /* Simple */
  padding: 0.3125rem 0.625rem; /* Multiple values */
  margin: 0.625rem 0.5rem; /* Existing rem */
  border-bottom: 0.0625rem solid black; /* Multiple mixed values */
  box-shadow: 0 0 0.125rem #ccc, inset 0 0 0.3125rem #eee; /* Comma-separated values */
  text-shadow: 0.0625rem 0.0625rem #eee, -0.0625rem 0 #eee; /* Alternate use */
}

Options

With baseline to 10 (html { font-size: 62.5%; }) and fallback to true:

.demo {
  font-size: 24px;
  font-size: 2.4rem; /* Simple */
  padding: 5px 10px;
  padding: 0.5rem 1rem; /* Multiple values */
  margin: 10px 5px;
  margin: 1rem 0.5rem; /* Existing rem */
  border-bottom: 1px solid black;
  border-bottom: 0.1rem solid black; /* Multiple mixed values */
  box-shadow: 0 0 2px #ccc, inset 0 0 5px #eee;
  box-shadow: 0 0 0.2rem #ccc, inset 0 0 0.5rem #eee; /* Comma-separated values */
  text-shadow: 1px 1px #eee, -1px 0 #eee;
  text-shadow: 0.1rem 0.1rem #eee, -0.1rem 0 #eee; /* Alternate use */
}

With convert to px (for a lt-ie9 only stylesheet for example):

.demo {
  font-size: 24px; /* Simple */
  padding: 5px 10px; /* Multiple values */
  margin: 10px 8px; /* Existing rem */
  border-bottom: 1px solid black; /* Multiple mixed values */
  box-shadow: 0 0 2px #ccc, inset 0 0 5px #eee; /* Comma-separated values */
  text-shadow: 1px 1px #eee, -1px 0 #eee; /* Alternate use */
}

Usage

Install with npm i postcss-rem and use with PostCSS:

postcss([require("postcss-rem")]);

Example with custom options:

postcss([
  require("postcss-rem")({
    name: "to-rem", // Default to 'rem'
    baseline: 10, // Default to 16
    // convert: "px", // Default to 'rem'
    fallback: true, // Default to false
    precision: 6, // Default to 5
  }),
]);

See PostCSS docs for examples for your environment.

Current Tags

  • 2.0.4                                ...           latest (2 years ago)

13 Versions

  • 2.0.4                                ...           2 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.5                                ...           5 years ago
  • 1.1.4                                ...           6 years ago
  • 1.1.3                                ...           6 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |