PostCSS plugin to scope styles using :not() pseudo-class
Adds the :not([your-selector])
pseudo-class to the allowed selectors of the processed CSS to prevent undesired styles having effect over certain elements.
A typical use case is to protect Web Components from styles inherited from the main document in browsers without Shadow DOM support.
:root {
--some-var: red;
}
html,
body {
margin: 0;
}
.some-class {
color: red;
}
.parent .child {
color: red;
}
:root {
--some-var: red;
}
html:not(.style-scope),
body:not(.style-scope) {
margin: 0;
}
.some-class:not(.style-scope) {
color: red;
}
.parent .child:not(.style-scope) {
color: red;
}
npm i -S postcss-selector-scope
const postcss = require('postcss');
const selectorScope = require('postcss-selector-scope');
const options = {
not: '.custom-selector',
exclude: ['.some-class']
};
postcss()
.use(selectorScope(options))
.process(cssFileContent)
.then((result) => console.log(result.css));
type: String
default: .style-scope
Selector used inside :not()
pseudo-class.
The default value is the one used by ShadyCSS library.
type: Array
default: []
List of selectors to exclude.
Each value can be a string or a regular expression.
:root
selector is excluded by default.
If you want to contribute, please read the CONTRIBUTING.md.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See the list of contributors who participated in this project.
This project is licensed under the MIT License.