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-inline-media

v1.4.0

Published

Media queries shortcut on PostCSS

Downloads

721

Readme

postcss-inline-media Build Status Coverage Status

A PostCSS plugin that allows you to write media queries properties on the same line.

.title {
  font-size: 20px @1200 18px @480 16px;
}

Installation

npm install postcss-inline-media

Usage

// PostCSS plugins
postcss([
  require('postcss-inline-media'),
]);

Check out PostCSS docs for the complete installation.

Example

You can inline media queries just by writing its condition next to an @ symbol.

If you only write a number after the @, it will be read as a max-width value in pixels, you can change this shorthand with the shorthand and shorthandUnit option of this plugin, e.g.:

require('postcss-inline-media')({
  shorthand: 'min-width',
  shorthandUnit: 'rem',
})

You can use the shorthandValueAddition to modify the shorthand media queries number values with a relative number to addition to it, e.g.:

require('postcss-inline-media')({
  shorthandValueAddition: -1',
})

This file:

.btn {
  margin: 20px 10px @(print) 10px 5px @600 5px 0;
}

will output:

.btn {
  margin: 20px 10px;
}
@media (print) {
  .btn {
    margin: 10px 5px;
  }
}
@media (max-width: 600px) {
  .btn {
    margin: 5px 0;
  }
}

Media queries variables

You can use postcss-simple-vars as media queries shortcut, put the postcss-simple-vars plugin after postcss-inline-media.

$md: (max-width: 900px);
.btn {
  padding: 20px @md 10px;
}

will output:

.btn {
  padding: 20px;
}
@media (max-width: 900px) {
  .btn {
    padding: 10px;
  }
}

Nested conditions

You can nest media queries in parentheses, but you can't set multiples nesting parentheses on the same CSS property.

div {
  margin: 50px (30px @(print) 20px @(max-width: 800px) 10px) 5px 5px;
}

will output:

div {
  margin: 50px 30px 5px 5px;
}
@media print {
  div {
    margin: 50px 20px 5px 5px;
  }
}
@media (max-width: 800px) {
  div {
    margin: 50px 10px 5px 5px;
  }
}

postcss-media-minmax

This plugin is compatible with postcss-media-minmax, put the postcss-media-minmax plugin after postcss-inline-media.

.btn {
  padding: 20px @(width <= 500px) 10px;
}

postcss-custom-media

You can also use postcss-custom-media, put the postcss-custom-media plugin after postcss-inline-media.

@custom-media --small-viewport (max-width: 30em);
.btn {
  padding: 20px @(--small-viewport) 10px;
}

Related

License

This project is licensed under the MIT license.