All Projects → arccoza → postcss-if-media

arccoza / postcss-if-media

Licence: MIT license
A PostCSS plugin to inline or nest media queries within CSS rules & properties.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to postcss-if-media

Postcss Start To End
PostCSS plugin that lets you control your layout (LTR or RTL) through logical rather than physical rules
Stars: ✭ 18 (-48.57%)
Mutual labels:  postcss, postcss-plugins
Postcss Font Family System Ui
PostCSS plugin to transform W3C CSS font-family: system-ui to a practical font-family list
Stars: ✭ 91 (+160%)
Mutual labels:  postcss, postcss-plugins
Stencil Postcss
Autoprefixer plugin for Stencil
Stars: ✭ 19 (-45.71%)
Mutual labels:  postcss, postcss-plugins
react-cli
基于 create-react-app 搭建的前端脚手架
Stars: ✭ 18 (-48.57%)
Mutual labels:  postcss, postcss-plugins
Postcss Aspect Ratio Mini
A PostCSS plugin to fix an element's dimensions to an aspect ratio
Stars: ✭ 123 (+251.43%)
Mutual labels:  postcss, postcss-plugins
Postcss Utilities
PostCSS plugin to add a collection of mixins, shortcuts, helpers and tools for your CSS
Stars: ✭ 293 (+737.14%)
Mutual labels:  postcss, postcss-plugins
Postcss At Rules Variables
PostCss plugin to use CSS Custom Properties in at-rule @each, @for, @if, @else and more...
Stars: ✭ 52 (+48.57%)
Mutual labels:  postcss, postcss-plugins
laggard
Automatically generate CSS fallbacks for legacy browsers, built on PostCSS
Stars: ✭ 23 (-34.29%)
Mutual labels:  postcss, postcss-plugins
Postcss Instagram
📷 PostCSS plugin for using Instagram filters in CSS
Stars: ✭ 111 (+217.14%)
Mutual labels:  postcss, postcss-plugins
Postcss High Contrast
Create high contrast version of your project with ease.
Stars: ✭ 108 (+208.57%)
Mutual labels:  postcss, postcss-plugins
postcss-sort-media-queries
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
Stars: ✭ 118 (+237.14%)
Mutual labels:  postcss, media-queries
Rucksack
A little bag of CSS superpowers, built on PostCSS
Stars: ✭ 1,861 (+5217.14%)
Mutual labels:  postcss, postcss-plugins
postcss-gtk
Processes GTK+ CSS into browser CSS
Stars: ✭ 23 (-34.29%)
Mutual labels:  postcss, postcss-plugins
Postcss Cssnext
`postcss-cssnext` has been deprecated in favor of `postcss-preset-env`.
Stars: ✭ 5,388 (+15294.29%)
Mutual labels:  postcss, postcss-plugins
postcss-inline-media
Media queries shortcut, built on PostCSS, example: font-size: 20px @1200 18px @480 16px;
Stars: ✭ 47 (+34.29%)
Mutual labels:  postcss, media-queries
Postcss Selector Not
PostCSS plugin to transform :not() W3C CSS level 4 pseudo class to more compatible CSS (multiple css3 :not() selectors)
Stars: ✭ 49 (+40%)
Mutual labels:  postcss, postcss-plugins
Postcss Plugins
The "officially unofficial" consolidated list of PostCSS plugins in a ready-to-use package
Stars: ✭ 107 (+205.71%)
Mutual labels:  postcss, postcss-plugins
Postcss Px To Viewport
A plugin for PostCSS that generates viewport units (vw, vh, vmin, vmax) from pixel units. The best choice to create a scalable interface on different displays by one design size.
Stars: ✭ 1,997 (+5605.71%)
Mutual labels:  postcss, media-queries
Stylefmt
stylefmt is a tool that automatically formats stylesheets.
Stars: ✭ 2,123 (+5965.71%)
Mutual labels:  postcss, postcss-plugins
rupture-sass
Better media queries mixins library for SASS
Stars: ✭ 47 (+34.29%)
Mutual labels:  media-queries

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;
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].