Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tobua/postcss-tags-without-class

Make HTML Tags Opt Out-Able When Adding a Class
https://github.com/tobua/postcss-tags-without-class

postcss postcss-plugin

Last synced: 1 day ago
JSON representation

Make HTML Tags Opt Out-Able When Adding a Class

Awesome Lists containing this project

README

        

# postcss-tags-without-class

Applies tag selectors only if no class is present on the tag.

## Only Style Pure Tags

```css
button {
color: red;
}
```

```html
I'm red.
I'm still black.
```

## Installation and Usage

```
npm i postcss postcss-tags-without-class
```

```js
const postcss = require('postcss')
const tagsWithoutClass = require('postcss-tags-without-class')

postcss([tagsWithoutClass]).process('button {color: red;}').then(result => {
const transformedCSS = result.css

transformedCSS === 'button:not([class]){color: red;}' // true
})
```

## How?

This plugin will add `:not([class])` to each tag. Multiple tags `button, a`, chained tags `ul li` and tags with pseudo classes `button:focus` are supported as well.

```css
button {}

button,
a {}

button:focus {}

a span {}
```

will become

```css
button:not([class]) {}

button:not([class]),
a:not([class]) {}

button:not([class]):focus {}

a:not([class]) span:not([class]) {}
```

## License

MIT