| 1 | # PostCSS Double Position Gradients [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
|
|---|
| 2 |
|
|---|
| 3 | [<img alt="NPM Version" src="https://img.shields.io/npm/v/postcss-double-position-gradients.svg" height="20">][npm-url]
|
|---|
| 4 | [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/double-position-gradients.svg" height="20">][css-url]
|
|---|
| 5 | [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|---|
| 6 |
|
|---|
| 7 | [PostCSS Double Position Gradients] lets you use double-position gradients in
|
|---|
| 8 | CSS, following the [CSS Image Values and Replaced Content] specification.
|
|---|
| 9 |
|
|---|
| 10 | ```pcss
|
|---|
| 11 | .linear-gradient {
|
|---|
| 12 | background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | .conic-gradient {
|
|---|
| 16 | background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | /* becomes */
|
|---|
| 20 |
|
|---|
| 21 | .linear-gradient {
|
|---|
| 22 | background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
|
|---|
| 23 | background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | .conic-gradient {
|
|---|
| 27 | background-image: conic-gradient(yellowgreen 40%, gold 0deg, gold 75%, #f06 0deg);
|
|---|
| 28 | background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
|
|---|
| 29 | }
|
|---|
| 30 | ```
|
|---|
| 31 |
|
|---|
| 32 | ## Usage
|
|---|
| 33 |
|
|---|
| 34 | Add [PostCSS Double Position Gradients] to your project:
|
|---|
| 35 |
|
|---|
| 36 | ```bash
|
|---|
| 37 | npm install postcss-double-position-gradients --save-dev
|
|---|
| 38 | ```
|
|---|
| 39 |
|
|---|
| 40 | Use [PostCSS Double Position Gradients] to process your CSS:
|
|---|
| 41 |
|
|---|
| 42 | ```js
|
|---|
| 43 | const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|---|
| 44 |
|
|---|
| 45 | postcssDoublePositionGradients.process(YOUR_CSS /*, processOptions, pluginOptions */);
|
|---|
| 46 | ```
|
|---|
| 47 |
|
|---|
| 48 | Or use it as a [PostCSS] plugin:
|
|---|
| 49 |
|
|---|
| 50 | ```js
|
|---|
| 51 | const postcss = require('postcss');
|
|---|
| 52 | const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|---|
| 53 |
|
|---|
| 54 | postcss([
|
|---|
| 55 | postcssDoublePositionGradients(/* pluginOptions */)
|
|---|
| 56 | ]).process(YOUR_CSS /*, processOptions */);
|
|---|
| 57 | ```
|
|---|
| 58 |
|
|---|
| 59 | [PostCSS Double Position Gradients] runs in all Node environments, with special 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 double-position gradients
|
|---|
| 69 | should be preserved. By default, double-position gradients are preserved.
|
|---|
| 70 |
|
|---|
| 71 | ```js
|
|---|
| 72 | postcssDoublePositionGradients({ preserve: false })
|
|---|
| 73 | ```
|
|---|
| 74 |
|
|---|
| 75 | ```css
|
|---|
| 76 | .linear-gradient {
|
|---|
| 77 | background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | .conic-gradient {
|
|---|
| 81 | background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /* becomes */
|
|---|
| 85 |
|
|---|
| 86 | .linear-gradient {
|
|---|
| 87 | background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | .conic-gradient {
|
|---|
| 91 | background-image: conic-gradient(yellowgreen 40%, gold 0deg, gold 75%, #f06 0deg);
|
|---|
| 92 | }
|
|---|
| 93 | ```
|
|---|
| 94 |
|
|---|
| 95 | ### enableProgressiveCustomProperties
|
|---|
| 96 |
|
|---|
| 97 | The `enableProgressiveCustomProperties` option determines whether the original notation
|
|---|
| 98 | is wrapped with `@supports` when used in Custom Properties. By default, it is enabled.
|
|---|
| 99 |
|
|---|
| 100 | ⚠️ We only recommend disabling this when you set `preserve` to `false` or if you bring your own fix for Custom Properties. See what the plugin does in its [README](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-progressive-custom-properties#readme).
|
|---|
| 101 |
|
|---|
| 102 | ```js
|
|---|
| 103 | postcssDoublePositionGradients({ enableProgressiveCustomProperties: false })
|
|---|
| 104 | ```
|
|---|
| 105 |
|
|---|
| 106 | ```pcss
|
|---|
| 107 | :root {
|
|---|
| 108 | --a-gradient: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | /* becomes */
|
|---|
| 112 |
|
|---|
| 113 | :root {
|
|---|
| 114 | --a-gradient: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%); /* will never be used, not even in older browser */
|
|---|
| 115 | --a-gradient: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
|
|---|
| 116 | }
|
|---|
| 117 | ```
|
|---|
| 118 |
|
|---|
| 119 | [css-url]: https://cssdb.org/#double-position-gradients
|
|---|
| 120 | [discord]: https://discord.gg/bUadyRwkJS
|
|---|
| 121 | [npm-url]: https://www.npmjs.com/package/postcss-double-position-gradients
|
|---|
| 122 |
|
|---|
| 123 | [CSS Image Values and Replaced Content]: https://www.w3.org/TR/css-images-4/#color-stop-syntax
|
|---|
| 124 | [PostCSS]: https://github.com/postcss/postcss
|
|---|
| 125 | [PostCSS Double Position Gradients]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-double-position-gradients
|
|---|