|
1 | 1 | # postcss-responsify |
2 | | -[PostCSS](https://github.com/postcss/postcss) plugin to create responsive classes for all styles within a `@responsive {}` rule. |
| 2 | +[PostCSS](https://github.com/postcss/postcss) plugin to create responsive classes with the `@responsive` rule. |
| 3 | + |
| 4 | +```javascript |
| 5 | +const postcss = require('postcss'); |
| 6 | +const responsify = require('postcss-responsify'); |
| 7 | + |
| 8 | +const breakpoints = [ |
| 9 | + { prefix: 'sm-', mediaQuery: '(min-width: 40em)' }, |
| 10 | + { prefix: 'md-', mediaQuery: '(min-width: 52em)' }, |
| 11 | +] |
| 12 | +postcss() |
| 13 | + .use(responsify()({ |
| 14 | + breakpoints |
| 15 | + })); |
| 16 | +``` |
| 17 | + |
| 18 | +**PostCSS** |
| 19 | +```css |
| 20 | +@responsive { |
| 21 | + .col { float: left; box-sizing: border-box; } |
| 22 | + .col-1 { width: calc(1/12 * 100%); } |
| 23 | + .col-2 { width: calc(2/12 * 100%); } |
| 24 | + .col-3 { width: calc(2/12 * 100%); } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +**CSS** |
| 29 | +```css |
| 30 | +.col { float: left; box-sizing: border-box; } |
| 31 | +.col-1 { width: calc(1/12 * 100%); } |
| 32 | +.col-2 { width: calc(2/12 * 100%); } |
| 33 | +.col-3 { width: calc(2/12 * 100%); } |
| 34 | + |
| 35 | +@media (min-width: 40em) { |
| 36 | + .sm-col { float: left; box-sizing: border-box; } |
| 37 | + .sm-col-1 { width: calc(1/12 * 100%); } |
| 38 | + .sm-col-2 { width: calc(2/12 * 100%); } |
| 39 | + .sm-col-3 { width: calc(2/12 * 100%); } |
| 40 | +} |
| 41 | + |
| 42 | +@media (min-width: 52em) { |
| 43 | + .md-col { float: left; box-sizing: border-box; } |
| 44 | + .md-col-1 { width: calc(1/12 * 100%); } |
| 45 | + .md-col-2 { width: calc(2/12 * 100%); } |
| 46 | + .md-col-3 { width: calc(2/12 * 100%); } |
| 47 | +} |
| 48 | +``` |
0 commit comments