| 1 | # PostCSS Unset Value [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 | [<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/postcss-unset-value.svg" height="20">][npm-url]
|
|---|
| 5 | [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/unset-value.svg" height="20">][css-url]
|
|---|
| 6 | [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
|
|---|
| 7 | [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|---|
| 8 |
|
|---|
| 9 | [PostCSS Unset Value] lets you use the unset keyword, following the [CSS Cascading and Inheritance] specification.
|
|---|
| 10 |
|
|---|
| 11 | ```pcss
|
|---|
| 12 | .color {
|
|---|
| 13 | color: unset;
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | .border-color {
|
|---|
| 17 | border-color: unset;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | .margin {
|
|---|
| 21 | margin: unset;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | /* becomes */
|
|---|
| 26 | .color {
|
|---|
| 27 | color: inherit;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | .border-color {
|
|---|
| 31 | border-color: initial;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | .margin {
|
|---|
| 35 | margin: initial;
|
|---|
| 36 | }
|
|---|
| 37 | ```
|
|---|
| 38 |
|
|---|
| 39 | ## Usage
|
|---|
| 40 |
|
|---|
| 41 | Add [PostCSS Unset Value] to your project:
|
|---|
| 42 |
|
|---|
| 43 | ```bash
|
|---|
| 44 | npm install postcss @csstools/postcss-unset-value --save-dev
|
|---|
| 45 | ```
|
|---|
| 46 |
|
|---|
| 47 | Use it as a [PostCSS] plugin:
|
|---|
| 48 |
|
|---|
| 49 | ```js
|
|---|
| 50 | const postcss = require('postcss');
|
|---|
| 51 | const postcssUnsetValue = require('@csstools/postcss-unset-value');
|
|---|
| 52 |
|
|---|
| 53 | postcss([
|
|---|
| 54 | postcssUnsetValue(/* pluginOptions */)
|
|---|
| 55 | ]).process(YOUR_CSS /*, processOptions */);
|
|---|
| 56 | ```
|
|---|
| 57 |
|
|---|
| 58 | [PostCSS Unset Value] runs in all Node environments, with special
|
|---|
| 59 | instructions for:
|
|---|
| 60 |
|
|---|
| 61 | | [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) |
|
|---|
| 62 | | --- | --- | --- | --- | --- | --- |
|
|---|
| 63 |
|
|---|
| 64 | ## Options
|
|---|
| 65 |
|
|---|
| 66 | ### preserve
|
|---|
| 67 |
|
|---|
| 68 | The `preserve` option determines whether the original source
|
|---|
| 69 | is preserved. By default, it is not preserved.
|
|---|
| 70 |
|
|---|
| 71 | ```js
|
|---|
| 72 | postcssUnsetValue({ preserve: true })
|
|---|
| 73 | ```
|
|---|
| 74 |
|
|---|
| 75 | ```pcss
|
|---|
| 76 | .color {
|
|---|
| 77 | color: unset;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | .border-color {
|
|---|
| 81 | border-color: unset;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | .margin {
|
|---|
| 85 | margin: unset;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | /* becomes */
|
|---|
| 89 |
|
|---|
| 90 | .color {
|
|---|
| 91 | color: inherit;
|
|---|
| 92 | color: unset;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | .border-color {
|
|---|
| 96 | border-color: initial;
|
|---|
| 97 | border-color: unset;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | .margin {
|
|---|
| 101 | margin: initial;
|
|---|
| 102 | margin: unset;
|
|---|
| 103 | }
|
|---|
| 104 | ```
|
|---|
| 105 |
|
|---|
| 106 | [postcss]: https://github.com/postcss/postcss
|
|---|
| 107 |
|
|---|
| 108 | [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|---|
| 109 | [css-url]: https://cssdb.org/#unset-value
|
|---|
| 110 | [discord]: https://discord.gg/bUadyRwkJS
|
|---|
| 111 | [npm-url]: https://www.npmjs.com/package/@csstools/postcss-unset-value
|
|---|
| 112 |
|
|---|
| 113 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|---|
| 114 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|---|
| 115 | [PostCSS]: https://github.com/postcss/postcss
|
|---|
| 116 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|---|
| 117 | [CSS Cascading and Inheritance]: https://www.w3.org/TR/css-cascade-4/#inherit-initial
|
|---|
| 118 | [PostCSS Unset Value]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-unset-value
|
|---|