blob: 932c06c663ebbae8e7ec6746d3e4d5316bfd9347 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# UnNth [![Build Status][ci-img]][ci]
<img align="right" width="135" height="95" src="http://postcss.github.io/postcss/logo-leftp.png" title="Philosopher’s stone, logo of PostCSS">
[UnNth] replaces `:nth-child` selectors with `:first-child` selectors. This can be useful when outputting CSS for older browsers like Internet Explorer 8.
```css
/* before */
.container > p:nth-child(4).specific > span {
font-weight: bold;
}
/* after */
.container > :first-child + * + * + p.specific > span {
font-weight: bold;
}
```
## Usage
Add [UnNth] to your build tool:
```bash
npm install postcss-unnth --save-dev
```
#### Node
```js
require('postcss-unnth')({ /* options */ }).process(YOUR_CSS);
```
#### PostCSS
Add [PostCSS] to your build tool:
```bash
npm install postcss --save-dev
```
Load [UnNth] as a PostCSS plugin:
```js
postcss([
require('postcss-unnth')({ /* options */ })
]);
```
#### Gulp
Add [Gulp PostCSS] to your build tool:
```bash
npm install gulp-postcss --save-dev
```
Enable [UnNth] within your Gulpfile:
```js
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./css/src/*.css').pipe(
postcss([
require('postcss-unnth')({ /* options */ })
])
).pipe(
gulp.dest('./css')
);
});
```
#### Grunt
Add [Grunt PostCSS] to your build tool:
```bash
npm install grunt-postcss --save-dev
```
Enable [UnNth] within your Gruntfile:
```js
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('postcss-unnth')({ /* options */ })
]
},
dist: {
src: 'css/*.css'
}
}
});
```
[ci]: https://travis-ci.org/jonathantneal/postcss-unnth
[ci-img]: https://travis-ci.org/jonathantneal/postcss-unnth.svg
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[PostCSS]: https://github.com/postcss/postcss
[UnNth]: https://github.com/jonathantneal/postcss-unnth
|