All Projects → dimitrinicolas → postcss-inline-media

dimitrinicolas / postcss-inline-media

Licence: MIT license
Media queries shortcut, built on PostCSS, example: font-size: 20px @1200 18px @480 16px;

Programming Languages

javascript
184084 projects - #8 most used programming language

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

postcss-sort-media-queries
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
Stars: ✭ 118 (+151.06%)
Mutual labels:  postcss, postcss-plugin, media-queries
Container Query
A PostCSS plugin and Javascript runtime combination, which allows you to write container queries in your CSS the same way you would write media queries.
Stars: ✭ 119 (+153.19%)
Mutual labels:  postcss, postcss-plugin
Postcss Plugins
The "officially unofficial" consolidated list of PostCSS plugins in a ready-to-use package
Stars: ✭ 107 (+127.66%)
Mutual labels:  postcss, postcss-plugin
Postcss Viewport Height Correction
PostCSS plugin to solve the popular problem when 100vh doesn’t fit the mobile browser screen.
Stars: ✭ 137 (+191.49%)
Mutual labels:  postcss, postcss-plugin
postcss-if-media
A PostCSS plugin to inline or nest media queries within CSS rules & properties.
Stars: ✭ 35 (-25.53%)
Mutual labels:  postcss, media-queries
Postcss Less
PostCSS Syntax for parsing LESS
Stars: ✭ 93 (+97.87%)
Mutual labels:  postcss, postcss-plugin
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 (+4148.94%)
Mutual labels:  postcss, media-queries
Postcss Import
PostCSS plugin to inline @import rules content
Stars: ✭ 1,048 (+2129.79%)
Mutual labels:  postcss, postcss-plugin
Postcss Spiffing
PostCSS plugin to use British English
Stars: ✭ 158 (+236.17%)
Mutual labels:  postcss, postcss-plugin
postcss-trash-killer
It is a postcss plugin which wil be remove all unused css
Stars: ✭ 20 (-57.45%)
Mutual labels:  postcss, postcss-plugin
postcss-import-url
PostCSS plugin inlines remote files.
Stars: ✭ 47 (+0%)
Mutual labels:  postcss, postcss-plugin
Postcss Prefix Selector
Prefix all CSS rules with a selector
Stars: ✭ 75 (+59.57%)
Mutual labels:  postcss, postcss-plugin
Postcss Nested Props
PostCSS plugin to unwrap nested properties.
Stars: ✭ 58 (+23.4%)
Mutual labels:  postcss, postcss-plugin
Rtlcss
Framework for transforming Cascading Style Sheets (CSS) from Left-To-Right (LTR) to Right-To-Left (RTL)
Stars: ✭ 1,363 (+2800%)
Mutual labels:  postcss, postcss-plugin
Postcss Triangle
PostCSS plugin to create a triangle.
Stars: ✭ 57 (+21.28%)
Mutual labels:  postcss, postcss-plugin
Postcss Aspect Ratio Mini
A PostCSS plugin to fix an element's dimensions to an aspect ratio
Stars: ✭ 123 (+161.7%)
Mutual labels:  postcss, postcss-plugin
postcss-input-style
PostCSS plugin that adds new pseudo-elements for easily styling the inner elements of inputs
Stars: ✭ 16 (-65.96%)
Mutual labels:  postcss, postcss-plugin
Postcss Icon
PostCSS plugin that adds `css icons` from icon sets
Stars: ✭ 20 (-57.45%)
Mutual labels:  postcss, postcss-plugin
Postcss Alias
PostCSS plugin that allows you to create aliases for CSS properties
Stars: ✭ 47 (+0%)
Mutual labels:  postcss, postcss-plugin
Postcss Rtl
PostCSS plugin for RTL-adaptivity
Stars: ✭ 143 (+204.26%)
Mutual labels:  postcss, postcss-plugin

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.

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].