Gathering detailed insights and metrics for postcss-media-minmax
Gathering detailed insights and metrics for postcss-media-minmax
Gathering detailed insights and metrics for postcss-media-minmax
Gathering detailed insights and metrics for postcss-media-minmax
@csstools/postcss-media-minmax
Use the range notation in CSS media queries
postcss-custom-media
Use Custom Media Queries in CSS
css-prefers-color-scheme
Use light and dark color schemes in all browsers
@csstools/postcss-media-queries-aspect-ratio-number-values
Use number values in aspect-ratio media queries.
Writing simple and graceful Media Queries!
npm install postcss-media-minmax
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
300 Stars
50 Commits
19 Forks
9 Watching
8 Branches
21 Contributors
Updated on 23 Oct 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-5.8%
884,776
Compared to previous day
Last week
1.5%
4,709,842
Compared to previous week
Last month
6.4%
19,924,405
Compared to previous month
Last year
-23.4%
255,347,979
Compared to previous year
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 4 and gives you access to the new features right away. Mom will never worry about my study any more. So amazing!
$ npm install postcss-media-minmax
Example 1:
1var fs = require('fs') 2var postcss = require('postcss') 3var minmax = require('postcss-media-minmax') 4 5var css = fs.readFileSync('input.css', 'utf8') 6 7var output = postcss() 8 .use(minmax()) 9 .process(css) 10 .css 11 12console.log('\n====>Output CSS:\n', output)
Or just:
1var output = postcss(minmax()) 2 .process(css) 3 .css
input.css:
1@media screen and (width >= 500px) and (width <= 1200px) { 2 .bar { 3 display: block; 4 } 5}
You will get:
1@media screen and (min-width: 500px) and (max-width: 1200px) { 2 .bar { 3 display: block; 4 } 5}
<mf-range> = <mf-name> [ '<' | '>' ]? '='? <mf-value>
| <mf-value> [ '<' | '>' ]? '='? <mf-name>
| <mf-value> '<' '='? <mf-name> '<' '='? <mf-value>
| <mf-value> '>' '='? <mf-name> '>' '='? <mf-value>
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
1@media screen and (device-aspect-ratio: 16 / 9) { 2 /* rules */ 3} 4 5/* equivalent to */ 6@media screen and (device-aspect-ratio: 16/9) { 7 /* rules */ 8}
The
1@media screen and (grid: -0) { 2 /* rules */ 3} 4 5/* equivalent to */ 6@media screen and (grid: 0) { 7 /* rules */ 8}
In Example 1, if a feature has both >=
and <=
logic, it can be written as follows:
1@media screen and (500px <= width <= 1200px) { 2 .bar { 3 display: block; 4 } 5} 6/* Or */ 7@media screen and (1200px >= width >= 500px) { 8 .bar { 9 display: block; 10 } 11}
Which will output:
1@media screen and (min-width: 500px) and (max-width: 1200px) { 2 .bar { 3 display: block; 4 } 5}
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.
1@media screen and (1200px <= width >= 500px) { 2 .bar { 3 display: block; 4 } 5}
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
@custom-media
& Node Watch1var fs = require('fs') 2var chokidar = require('chokidar') 3var postcss = require('postcss') 4var minmax = require('postcss-media-minmax') 5var customMedia = require('postcss-custom-media') 6 7var src = 'input.css' 8 9console.info('Watching…\nModify the input.css and save.') 10 11 12chokidar.watch(src, { 13 ignored: /[\/\\]\./, 14 persistent: true 15}).on('all', 16 function(event, path, stats) { 17 var css = fs.readFileSync(src, 'utf8') 18 var output = postcss() 19 .use(customMedia()) 20 .use(minmax()) 21 .process(css) 22 .css; 23 fs.writeFileSync('output.css', output) 24 }) 25
input.css:
1@custom-media --foo (width >= 20em) and (width <= 50em); 2@custom-media --bar (height >= 300px) and (height <= 600px); 3 4@media (--foo) and (--bar) { 5 6}
output.css:
1@media (min-width: 20em) and (max-width: 50em) and (min-height: 300px) and (max-height: 600px) { 2 3}
1module.exports = function(grunt) { 2 grunt.initConfig({ 3 pkg: grunt.file.readJSON('package.json'), 4 postcss: { 5 options: { 6 processors: [ 7 require('autoprefixer-core')({ browsers: ['> 0%'] }).postcss, //Other plugin 8 require('postcss-media-minmax')(), 9 ] 10 }, 11 dist: { 12 src: ['src/*.css'], 13 dest: 'build/grunt.css' 14 } 15 } 16 }); 17 18 grunt.loadNpmTasks('grunt-contrib-uglify'); 19 grunt.loadNpmTasks('grunt-postcss'); 20 21 grunt.registerTask('default', ['postcss']); 22}
1var gulp = require('gulp'); 2var rename = require('gulp-rename'); 3var postcss = require('gulp-postcss'); 4var selector = require('postcss-media-minmax') 5var autoprefixer = require('autoprefixer-core') 6 7gulp.task('default', function () { 8 var processors = [ 9 autoprefixer({ browsers: ['> 0%'] }), //Other plugin 10 minmax() 11 ]; 12 gulp.src('src/*.css') 13 .pipe(postcss(processors)) 14 .pipe(rename('gulp.css')) 15 .pipe(gulp.dest('build')) 16}); 17gulp.watch('src/*.css', ['default']);
$ git clone https://github.com/postcss/postcss-media-minmaxs.git
$ git checkout -b patch
$ npm install
$ npm test
Thank the author of PostCSS Andrey Sitnik for giving us such simple and easy CSS syntax analysis tools.
Thank Tab Atkins Jr. for writing the specs of Media Queries Level 4.
Thank ziyunfei for suggestions and help of this plugin.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More