Socket
Socket
Sign inDemoInstall

postcss-nesting

Package Overview
Dependencies
1
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-nesting


Version published
Maintainers
1
Created

Package description

What is postcss-nesting?

The postcss-nesting package is a PostCSS plugin that allows you to use nesting syntax in CSS, similar to what is offered by preprocessors like Sass and Less. It helps to write more readable and maintainable CSS by allowing styles to be nested within one another.

What are postcss-nesting's main functionalities?

Nesting Rules

Allows nesting of selectors within a parent selector, which will be expanded to the equivalent of 'a b { color: black; }'.

a {
  & b { color: black; }
}

Nesting Properties

Enables nesting of properties, which is useful for grouping font properties or other related properties together.

a {
  font: {
    weight: bold;
    size: 1em;
    family: serif;
  }
}

Nesting At-Rules

Supports nesting of at-rules like @media within a selector, which will be processed into the correct CSS syntax.

a {
  @media (min-width: 500px) {
    color: black;
  }
}

Other packages similar to postcss-nesting

Readme

Source

CSS Nesting Build Status

CSS Nesting is a PostCSS plugin that allows you to nest one style rule inside another, following the CSS Nesting Module Level 3 specification.

/* before */

a, b {
    color: red;

    @nest c, d {
        color: white;

    @nest & & {
        color: blue;
    }

    @nest &:hover {
        color: black;
    }

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

/* after */

a, b {
    color: red;
}

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

a a, a b, b a, b b {
    color: blue;
}

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

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

Usage

Follow these steps to use CSS Nesting.

Add CSS Nesting to your build tool:

npm install postcss-nesting --save-dev
Node

Use CSS Nesting directly:

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

Add PostCSS to your build tool:

npm install postcss --save-dev

Use CSS Nesting as a PostCSS plugin:

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

Add Gulp PostCSS to your build tool:

npm install gulp-postcss --save-dev

Use CSS Nesting within your Gulpfile:

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

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

Add Grunt PostCSS to your build tool:

npm install grunt-postcss --save-dev

Use CSS Nesting within your Gruntfile:

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
    postcss: {
        options: {
            processors: [
                require('postcss-nesting')({ /* options */ })
            ]
        },
        dist: {
            src: 'css/*.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

FAQs

Last updated on 22 Sep 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc