Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-px-to-em

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-px-to-em

PostCSS plugin to convert all px measurements to em

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

PostCSS px To em Build Status

PostCSS plugin to convert all px measurements to em.

.foo {
  width: 270px;
  margin: 0 15px;
  padding: 1em;

  /* you can override pixel replacement by adding a "force" *
   * comment after the pixel measurement you want to keep.  */
  border-radius: 10px /*force*/ 16px;
}

@media (min-width: 640px) {
  /* doesn't change pixel values used for media queries, as this wouldn't work properly */
  .foo {
    width: 100%;
    padding: 10px;
  }
}
.foo {
  width: 16.875em;
  margin: 0 0.9375em;
  padding: 1em;

  /* you can override pixel replacement by adding a "force" *
   * comment after the pixel measurement you want to keep.  */
  border-radius: 10px /*force*/ 1em;
}

@media (min-width: 640px) {
  /* doesn't change pixel values used for media queries, as this wouldn't work properly */
  .foo {
    width: 100%;
    padding: 0.625em;
  }
}

Rationale

For Bugherd, we needed to be able to scale our UIs to fit any zoom level on Mobile. To enable this, we change the parents' font-size and use em measurements relative to the base font size (usually 16px) in our components. This PostCSS plugin facilitates this, without requiring us to rewrite all our code to use em manually.

Usage

Plug it into your PostCSS configuration.

var options = {
  base: 16, // Base font size; 16px by default
};

// Options may be supplied as the first argument, but are not required.
postcss([require('postcss-px-to-em')(options)])

See PostCSS docs for examples for your environment.

Keywords

FAQs

Package last updated on 06 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc