Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
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.
PostCSS Nesting is a PostCSS plugin that transforms W3C CSS Nesting Module Level 3 syntax (@tabatkins’ proposal) to more compatible CSS.
/* before */
a, b {
color: red;
{
c, d {
color: white;
}
& & {
color: blue;
}
&:hover {
color: white;
}
}
}
/* 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: white;
}
From CSS Nesting Module Level 3:
This module introduces the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. This increase the modularity and maintainability of CSS stylesheets.
You just need to follow these two steps to use PostCSS Nesting:
npm install postcss-nesting --save-dev
postcss([ require('postcss-nesting')({ /* options */ }) ])
Install Grunt PostCSS:
npm install postcss-nesting --save-dev
Enable PostCSS Nesting within your Gruntfile:
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('postcss-nesting')({ /* options */ })
]
},
dist: {
src: 'css/*.css'
}
}
});
FAQs
Nest rules inside each other in CSS
The npm package postcss-nesting receives a total of 5,169,121 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 0 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.