| [9af201e] | 1 | # PostCSS Selector Not [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
|
|---|
| 2 |
|
|---|
| 3 | [<img alt="npm version" src="https://img.shields.io/npm/v/postcss-selector-not.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/not-pseudo-class.svg" height="20">][css-url] [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url] [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|---|
| 4 |
|
|---|
| 5 | [PostCSS Selector Not] transforms :not() W3C CSS level 4 pseudo classes to :not() CSS level 3 selectors following the [Selectors 4 Specification].
|
|---|
| 6 |
|
|---|
| 7 | ```pcss
|
|---|
| 8 | p:not(:first-child, .special) {
|
|---|
| 9 | color: red;
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | /* becomes */
|
|---|
| 13 |
|
|---|
| 14 | p:not(:first-child):not(.special) {
|
|---|
| 15 | color: red;
|
|---|
| 16 | }
|
|---|
| 17 | ```
|
|---|
| 18 |
|
|---|
| 19 | ⚠️ Only lists of simple selectors (`:not(.a, .b)`) will work as expected.
|
|---|
| 20 | Complex selectors (`:not(.a > .b, .c ~ .d)`) can not be downgraded.
|
|---|
| 21 |
|
|---|
| 22 | ## Usage
|
|---|
| 23 |
|
|---|
| 24 | Add [PostCSS Selector Not] to your project:
|
|---|
| 25 |
|
|---|
| 26 | ```bash
|
|---|
| 27 | npm install postcss postcss-selector-not --save-dev
|
|---|
| 28 | ```
|
|---|
| 29 |
|
|---|
| 30 | Use it as a [PostCSS] plugin:
|
|---|
| 31 |
|
|---|
| 32 | ```js
|
|---|
| 33 | const postcss = require('postcss');
|
|---|
| 34 | const postcssSelectorNot = require('postcss-selector-not');
|
|---|
| 35 |
|
|---|
| 36 | postcss([
|
|---|
| 37 | postcssSelectorNot(/* pluginOptions */)
|
|---|
| 38 | ]).process(YOUR_CSS /*, processOptions */);
|
|---|
| 39 | ```
|
|---|
| 40 |
|
|---|
| 41 | [PostCSS Selector Not] runs in all Node environments, with special
|
|---|
| 42 | instructions for:
|
|---|
| 43 |
|
|---|
| 44 | | [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
|
|---|
| 45 | | --- | --- | --- | --- | --- | --- |
|
|---|
| 46 |
|
|---|
| 47 | [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|---|
| 48 | [css-url]: https://cssdb.org/#not-pseudo-class
|
|---|
| 49 | [discord]: https://discord.gg/bUadyRwkJS
|
|---|
| 50 | [npm-url]: https://www.npmjs.com/package/postcss-selector-not
|
|---|
| 51 |
|
|---|
| 52 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|---|
| 53 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|---|
| 54 | [PostCSS]: https://github.com/postcss/postcss
|
|---|
| 55 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|---|
| 56 | [PostCSS Selector Not]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-selector-not
|
|---|
| 57 | [Selectors 4 Specification]: https://www.w3.org/TR/selectors-4/#negation-pseudo
|
|---|