Skip to content

Convert pixel units to rem (root em) units using PostCSS

License

Notifications You must be signed in to change notification settings

zhouhuafei-team/postcss-pxtorem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pxtorem

A CSS post-processor that generates rem units from pixel units.
Written with PostCSS.
This is essentially node-pixrem only reversed. All credit for goes to that project for the code base.

Usage

Pixels are the easiest unit to use. The only issue with them is that they don't let browsers change the default font size of 16. This script converts every px value to a rem to allow the browser to choose the font size.

Example

'use strict';
var fs = require('fs');
var pixrem = require('pxtorem');
var css = fs.readFileSync('main.css', 'utf8');
var processedCss = pixrem(css, '16');

fs.writeFile('main-rem.css', processedCss, function (err) {
  if (err) {
    throw err;
  }
  console.log('Hello font resizing.');
});

Parameters

css

Type: String

Some CSS to process.

rootvalue

Type: Number
Default: 16

The root element font size. Has to be a number that represents a pixel unit.

options

Type: Object | Null
Default: { replace: false }

  • replace replaces rules containing rems instead of adding fallbacks.

About

Convert pixel units to rem (root em) units using PostCSS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 96.7%
  • CSS 3.3%