source: frontend/node_modules/postcss-nesting/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.0 KB
Line 
1# PostCSS Nesting [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
2
3[![NPM Version][npm-img]][npm-url]
4[![CSS Standard Status][css-img]][css-url]
5[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
6
7[PostCSS Nesting] lets you nest style rules inside each other, following the
8[CSS Nesting] specification. If you want nested rules the same way [Sass] works
9you might want to use [PostCSS Nested] instead.
10
11```pcss
12a, b {
13 color: red;
14
15 /* "&" comes first */
16 & c, & d {
17 color: white;
18 }
19
20 /* "&" comes later, requiring "@nest" */
21 @nest e & {
22 color: yellow;
23 }
24}
25
26/* becomes */
27
28a, b {
29 color: red;
30}
31
32a c, a d, b c, b d {
33 color: white;
34}
35
36e a, e b {
37 color: yellow;
38}
39```
40
41## Usage
42
43Add [PostCSS Nesting] to your project:
44
45```bash
46npm install postcss-nesting --save-dev
47```
48
49Use [PostCSS Nesting] as a [PostCSS] plugin:
50
51```js
52import postcss from 'postcss';
53import postcssNesting from 'postcss-nesting';
54
55postcss([
56 postcssNesting(/* pluginOptions */)
57]).process(YOUR_CSS /*, processOptions */);
58```
59
60[PostCSS Nesting] runs in all Node environments, with special instructions for:
61
62| [Node](INSTALL.md#node) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
63| --- | --- | --- | --- | --- |
64
65### Deno
66
67You can also use [PostCSS Nesting] on [Deno]:
68
69```js
70import postcss from "https://deno.land/x/postcss/mod.js";
71import postcssNesting from "https://cdn.jsdelivr.net/npm/postcss-nesting@10/mod.js";
72
73await postcss([postcssNesting]).process(YOUR_CSS /*, processOptions */);
74```
75
76## Options
77
78### noIsPseudoSelector
79
80#### Specificity
81
82Before :
83
84```css
85#alpha,
86.beta {
87 &:hover {
88 order: 1;
89 }
90}
91```
92
93After **without** the option :
94
95```js
96postcssNesting()
97```
98
99```css
100:is(#alpha,.beta):hover {
101 order: 1;
102}
103```
104
105_`.beta:hover` has specificity as if `.beta` where an id selector, matching the specification._
106
107[specificity: 1, 1, 0](https://polypane.app/css-specificity-calculator/#selector=%3Ais(%23alpha%2C.beta)%3Ahover)
108
109After **with** the option :
110
111```js
112postcssNesting({
113 noIsPseudoSelector: true
114})
115```
116
117```css
118#alpha:hover, .beta:hover {
119 order: 1;
120}
121```
122
123_`.beta:hover` has specificity as if `.beta` where a class selector, conflicting with the specification._
124
125[specificity: 0, 2, 0](https://polypane.app/css-specificity-calculator/#selector=.beta%3Ahover)
126
127
128#### Complex selectors
129
130Before :
131
132```css
133.alpha > .beta {
134 & + & {
135 order: 2;
136 }
137}
138```
139
140After **without** the option :
141
142```js
143postcssNesting()
144```
145
146```css
147:is(.alpha > .beta) + :is(.alpha > .beta) {
148 order: 2;
149}
150```
151
152After **with** the option :
153
154```js
155postcssNesting({
156 noIsPseudoSelector: true
157})
158```
159
160```css
161.alpha > .beta + .alpha > .beta {
162 order: 2;
163}
164```
165
166_this is a different selector than expected as `.beta + .alpha` matches `.beta` followed by `.alpha`._<br>
167_avoid these cases when you disable `:is()`_<br>
168_writing the selector without nesting is advised here_
169
170```css
171/* without nesting */
172.alpha > .beta + .beta {
173 order: 2;
174}
175```
176
177### ⚠️ Spec disclaimer
178
179The [CSS Nesting Module] spec states on nesting that "Declarations occurring after a nested rule are invalid and ignored.".
180While we think it makes sense on browsers, enforcing this at the plugin level introduces several constraints that would
181interfere with PostCSS' plugin nature such as with `@mixin`
182
183[css-img]: https://cssdb.org/images/badges/nesting-rules.svg
184[css-url]: https://cssdb.org/#nesting-rules
185[discord]: https://discord.gg/bUadyRwkJS
186[npm-img]: https://img.shields.io/npm/v/postcss-nesting.svg
187[npm-url]: https://www.npmjs.com/package/postcss-nesting
188
189[CSS Nesting]: https://drafts.csswg.org/css-nesting-1/
190[PostCSS]: https://github.com/postcss/postcss
191[PostCSS Nesting]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting
192[Deno]: https://deno.land/x/postcss_nesting
193[PostCSS Nested]: https://github.com/postcss/postcss-nested
194[Sass]: https://sass-lang.com/
195[CSS Nesting Module]: https://www.w3.org/TR/css-nesting-1/
Note: See TracBrowser for help on using the repository browser.