npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-if-media

v1.0.3

Published

A PostCSS plugin to inline or nest media queries with CSS properties.

Downloads

54

Readme

PostCSS ?If Media Travis Build Status

A PostCSS plugin for adding ?if media queries inside rules and inline with property values. A great way to keep style values for different media queries neatly organized and grouped together under their natural rules. Use with PostCSS Media Minmax and PostCSS Custom Media for best effect (be sure to place postcss-if-media before postcss-media-minmax, and postcss-custom-media, or any other media query plugins).

Explanation

The plugin provides ?if media QUERY as an inline declaration and a nested block, where QUERY is any valid media query.

Any properties with the ?if media QUERY declaration following their value, or any properties inside an ?if media QUERY { } block will be extracted from their rule and placed in their own rule under an @media QUERY query.

The generated @media queries are placed directly after the original rule to maintain specificity.

Install

npm install postcss-if-media --save

Example 1

An inline declaration example.

/* Input. */
.test {
  position: relative;
  margin: 0 1em ?if media (min-width: 1025px);
  margin: 0 0.5em ?if media (min-width: 641px) and (max-width: 1024px);
  margin: 0 0.3em ?if media (max-width: 640px);
}

/* Output. */
.test {
  position: relative;
}

@media (min-width: 1025px) {
  .test {
     margin: 0 1em;
  }
}
@media (min-width: 641px) and (max-width: 1024px) {
  .test {
     margin: 0 0.5em;
  }
}
@media (max-width: 640px) {
  .test {
     margin: 0 0.3em;
  }
}

Example 2

A nested block example.

/* Input. */
.test {
  position: relative;
  ?if media (min-width: 1025px) {
    color: red;
    margin: 0 1em;
  }
  ?if media (min-width: 641px) and (max-width: 1024px) {
    color: green;
    margin: 0 0.5em;
  }
  ?if media (max-width: 640px) {
    color: blue;
    margin: 0 0.3em;
  }
}

/* Output. */
.test {
  position: relative;
}

@media (min-width: 1025px) {
  .test {
    color: red;
    margin: 0 1em;
  }
}
@media (min-width: 641px) and (max-width: 1024px) {
  .test {
    color: green;
    margin: 0 0.5em;
  }
}
@media (max-width: 640px) {
  .test {
    color: blue;
    margin: 0 0.3em;
  }
}