Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
postcss-nesting
Advanced tools
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.
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;
}
}
Similar to postcss-nesting, postcss-nested allows for nesting of selectors within CSS. It follows the nesting rules of preprocessors like Sass rather than the CSS Nesting Module.
This package includes postcss-nesting as one of its features, among other future CSS features, and allows you to use them in current browsers.
This is a syntax plugin for PostCSS that allows you to work with SCSS syntax, including nesting, but it does not compile SCSS. It's useful for linting SCSS with stylelint and PostCSS.
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;
}
}
/* 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;
}
}
Add CSS Nesting to your build tool:
npm install postcss-nesting --save-dev
require('postcss-nesting').process(YOUR_CSS, { /* options */ });
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 */);
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('.')
);
});
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'
}
}
});
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
).
FAQs
Nest rules inside each other in CSS
The npm package postcss-nesting receives a total of 4,818,941 weekly downloads. As such, postcss-nesting popularity was classified as popular.
We found that postcss-nesting demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.