Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
/ postcss-unnth Public archive

Replace :nth-child selectors with :first-child+ selectors

License

Notifications You must be signed in to change notification settings

csstools/postcss-unnth

Repository files navigation

UnNth Build Status

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;
}

Usage

Add UnNth to your build tool:

npm install postcss-unnth --save-dev

Node

require('postcss-unnth')({ /* options */ }).process(YOUR_CSS);

PostCSS

Add PostCSS to your build tool:

npm install postcss --save-dev

Load UnNth as a PostCSS plugin:

postcss([
    require('postcss-unnth')({ /* options */ })
]);

Gulp

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')
    );
});

Grunt

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'
        }
    }
});

About

Replace :nth-child selectors with :first-child+ selectors

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published