PostCSS ?If Media
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. */ /* Output. */ {}{}{}
Example 2
A nested block example.
/* Input. */ ?)) ?) } /* Output. */ {}{}{}