https://github.com/csstools/postcss-media-fn
Use media() to assign responsive values to a property
https://github.com/csstools/postcss-media-fn
Last synced: 11 months ago
JSON representation
Use media() to assign responsive values to a property
- Host: GitHub
- URL: https://github.com/csstools/postcss-media-fn
- Owner: csstools
- License: cc0-1.0
- Archived: true
- Created: 2017-01-03T03:20:25.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-11-08T11:48:05.000Z (over 4 years ago)
- Last Synced: 2025-04-25T05:06:16.650Z (11 months ago)
- Language: JavaScript
- Homepage: https://jonathantneal.github.io/postcss-media-fn/
- Size: 69.3 KB
- Stars: 15
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Media() [
][postcss]
[![NPM Version][npm-img]][npm-url]
[![Build Status][cli-img]][cli-url]
[![Licensing][lic-img]][lic-url]
[![Gitter Chat][git-img]][git-url]
[Media()] lets you use the `media()` function to assign responsive values to a declaration, following the [CSS Media Expressions] specification.
```css
/* before */
h1 {
font-size: media(
16px,
(min-width: 600px) 20px,
(min-width: 1000px) 40px,
(min-width: 1400px) 60px
);
}
/* 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:
```bash
npm install postcss-media-fn --save-dev
```
#### Node
```js
require('postcss-media-fn').process(YOUR_CSS, { /* options */ });
```
#### PostCSS
Add [PostCSS] to your build tool:
```bash
npm install postcss --save-dev
```
Load [Media()] as a PostCSS plugin:
```js
postcss([
require('postcss-media-fn')({ /* options */ })
]).process(YOUR_CSS, /* options */);
```
#### Gulp
Add [Gulp PostCSS] to your build tool:
```bash
npm install gulp-postcss --save-dev
```
Enable [Media()] within your Gulpfile:
```js
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:
```bash
npm install grunt-postcss --save-dev
```
Enable [Media()] within your Gruntfile:
```js
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
use: [
require('postcss-media-fn')({ /* options */ })
]
},
dist: {
src: '*.css'
}
}
});
```
[cli-url]: https://github.com/csstools/postcss-media-fn/actions/workflows/ci.yaml
[cli-img]: https://github.com/csstools/postcss-media-fn/actions/workflows/ci.yaml/badge.svg
[git-url]: https://gitter.im/postcss/postcss
[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg
[lic-url]: LICENSE.md
[lic-img]: https://img.shields.io/npm/l/postcss-media-fn.svg
[npm-url]: https://www.npmjs.com/package/postcss-media-fn
[npm-img]: https://img.shields.io/npm/v/postcss-media-fn.svg
[CSS Media Expressions]: https://jonathantneal.github.io/media-expressions-spec/
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[Media()]: https://github.com/jonathantneal/postcss-media-fn
[PostCSS]: https://github.com/postcss/postcss