UnNth replaces :nth-child
selectors with :first-child
selectors. This can be useful when outputting CSS for older browsers like Internet Explorer 8.
/* before */
.container > p:nth-child(4).specific > span {
font-weight: bold;
}
/* after */
.container > :first-child + * + * + p.specific > span {
font-weight: bold;
}
Add UnNth to your build tool:
npm install postcss-unnth --save-dev
require('postcss-unnth')({ /* options */ }).process(YOUR_CSS);
Add PostCSS to your build tool:
npm install postcss --save-dev
Load UnNth as a PostCSS plugin:
postcss([
require('postcss-unnth')({ /* options */ })
]);
Add Gulp PostCSS to your build tool:
npm install gulp-postcss --save-dev
Enable UnNth within your Gulpfile:
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')
);
});
Add Grunt PostCSS to your build tool:
npm install grunt-postcss --save-dev
Enable UnNth within your Gruntfile:
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('postcss-unnth')({ /* options */ })
]
},
dist: {
src: 'css/*.css'
}
}
});