githubEdit

PostCSS Media Minmax

CSS Standard Statusarrow-up-right Build Statusarrow-up-right NPM Downloadsarrow-up-right NPM Versionarrow-up-right Licensearrow-up-right

Writing simple and graceful media queries!

The min-width, max-width and many other properties of media queries are really confusing. I want to cry every time I see them. But right now according to the new specs, you can use more intuitive <= or >= to replace the min-/max- prefixes in media queries.

V2.1.0 began to support > or < symbol.

This is a polyfill plugin which supports CSS Media Queries Level 4arrow-up-right and gives you access to the new features right away. Mom will never worry about my study any more. So amazing!

简体中文


Gif Demo

Installation

Quick Start

Example 1:

Or just:

input.css:

You will get:

CSS syntax

syntax

PostCSS Media Minmax hasn't implemented syntax such as 200px > = width or 200px < = width currently because its readability is not good enough yet.

The special values:

  • The value type is a positive (not zero or negative) followed by optional whitespace, followed by a solidus ('/'), followed by optional whitespace, followed by a positive . s can be ordered or compared by transforming them into the number obtained by dividing their first by their second .

  • The value type is an with the value 0 or 1. Any other integer value is invalid. Note that -0 is always equivalent to 0 in CSS, and so is also accepted as a valid value.

How to use

Shorthand

In Example 1, if a feature has both >= and <= logic, it can be written as follows:

Which will output:

Note: When the media feature name is in the middle, we must ensure that two <= or >= are in the same direction, otherwise which will not be converted.

E.g. in the example below, width is greater than or equal to 500px and is greater than or equal to 1200px, which is the wrong in both grammar and logic.

Media feature names

The following properties support the min-/max- prefixes in the specifications at present, and will be automatically converted by PostCSS Media Minmax.

  • width

  • height

  • device-width

  • device-height

  • aspect-ratio

  • device-aspect-ratio

  • color

  • color-index

  • monochrome

  • resolution

Using with @custom-media & Node Watch

input.css:

output.css:

Grunt

Gulp

Contributing

Acknowledgements

Last updated