postcss-media-fn

3.0.0 • Public • Published

Media() PostCSS Logo

NPM Version Build Status Gitter Chat

Media() lets you use the media() function to assign responsive values to a declaration, following the CSS Media Expressions specification.

/* before */
 
h1 {
  font-size: media(
    16px,
    (min-width:  600px20px,
    (min-width: 1000px40px,
    (min-width: 1400px60px
  );
}
 
 
/* after */
 
h1 {
  font-size: 16px;
}
 
@media (min-width: 600px) {
  h1 {
    font-size: 20px;
  }
}
 
@media (min-width: 1000px) {
  h1 {
    font-size: 40px;
  }
}
 
@media (min-width: 1400px) {
  h1 {
    font-size: 60px;
  }
}

Usage

Add Media() to your build tool:

npm install postcss-media-fn --save-dev

Node

require('postcss-media-fn').process(YOUR_CSS, { /* options */ });

PostCSS

Add PostCSS to your build tool:

npm install postcss --save-dev

Load Media() as a PostCSS plugin:

postcss([
  require('postcss-media-fn')({ /* options */ })
]).process(YOUR_CSS, /* options */);

Gulp

Add Gulp PostCSS to your build tool:

npm install gulp-postcss --save-dev

Enable Media() within your Gulpfile:

var postcss = require('gulp-postcss');
 
gulp.task('css', function () {
  return gulp.src('./src/*.css').pipe(
    postcss([
      require('postcss-media-fn')({ /* options */ })
    ])
  ).pipe(
    gulp.dest('.')
  );
});

Grunt

Add Grunt PostCSS to your build tool:

npm install grunt-postcss --save-dev

Enable Media() within your Gruntfile:

grunt.loadNpmTasks('grunt-postcss');
 
grunt.initConfig({
  postcss: {
    options: {
      use: [
        require('postcss-media-fn')({ /* options */ })
      ]
    },
    dist: {
      src: '*.css'
    }
  }
});

Package Sidebar

Install

npm i postcss-media-fn

Weekly Downloads

24

Version

3.0.0

License

CC0-1.0

Last publish

Collaborators

  • romainmenke
  • alaguna
  • jonathantneal