Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

postcss-nesting

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-nesting

Transpiles nested rules according to CSS Nesting Module Level 3

Source
npmnpm
Version
2.2.0
Version published
Weekly downloads
7M
-0.01%
Maintainers
1
Weekly downloads
 
Created
Source

CSS Nesting

PostCSS Logo

NPM Version Build Status

CSS Nesting allows you to nest one style rule inside another, following the CSS Nesting Module Level 3 specification.

/* at rule nesting */

a, b {
	color: red;

	@nest & c, & d {
		color: white;
	}

	@nest & & {
		color: blue;
	}

	@nest &:hover {
		color: black;
	}

	@media (min-width: 30em) {
		color: yellow;
	}
}

/* direct nesting */

a, b {
	color: red;

	& c, & d {
		color: white;
	}

	& & {
		color: blue;
	}

	&:hover {
		color: black;
	}

	@media (min-width: 30em) {
		color: yellow;

		@media (min-device-pixel-ratio: 1.5) {
			color: green;
		}
	}
}

/* after */

a, b {
    color: red;
}

a c, a d, b c, b d {
    color: white;
}

a a, b b {
    color: blue;
}

a:hover, b:hover {
    color: black;
}

@media (min-width: 30em) {
    a, b {
        color: yellow;
    }
}

@media (min-width: 30em) and (min-device-pixel-ratio: 1.5) {
	color: green;
}

Usage

Add CSS Nesting to your build tool:

npm install postcss-nesting --save-dev

Node

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

PostCSS

Add PostCSS to your build tool:

npm install postcss --save-dev

Load CSS Nesting as a PostCSS plugin:

postcss([
	require('postcss-nesting')({ /* options */ })
]).process(YOUR_CSS, /* options */);

Gulp

Add Gulp PostCSS to your build tool:

npm install gulp-postcss --save-dev

Enable CSS Nesting within your Gulpfile:

var postcss = require('gulp-postcss');

gulp.task('css', function () {
	return gulp.src('./src/*.css').pipe(
		postcss([
			require('postcss-nesting')({ /* options */ })
		])
	).pipe(
		gulp.dest('.')
	);
});

Grunt

Add Grunt PostCSS to your build tool:

npm install grunt-postcss --save-dev

Enable CSS Nesting within your Gruntfile:

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
	postcss: {
		options: {
			use: [
				require('postcss-nesting')({ /* options */ })
			]
		},
		dist: {
			src: '*.css'
		}
	}
});

Options

bubble

Type: Array
Default: ['document', 'media', 'supports']

Specifies additional at-rules whose contents should be transpiled so that the at-rule comes first. By default, @media, @supports and @document will do this.

prefix

Type: String
Default: null

Specifies a prefix to be surrounded by dashes before the @nest at-rule (e.g. @-x-nest).

Keywords

postcss

FAQs

Package last updated on 30 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts