1 | # PostCSS Color Hex Alpha [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
|
---|
2 |
|
---|
3 | [![NPM Version][npm-img]][npm-url]
|
---|
4 | [![CSS Standard Status][css-img]][css-url]
|
---|
5 | [![Build Status][cli-img]][cli-url]
|
---|
6 | [![Support Chat][git-img]][git-url]
|
---|
7 |
|
---|
8 | [PostCSS Color Hex Alpha] lets you use 4 & 8 character hex color notation in
|
---|
9 | CSS, following the [CSS Color Module] specification.
|
---|
10 |
|
---|
11 | ```pcss
|
---|
12 | body {
|
---|
13 | background: #9d9c;
|
---|
14 | }
|
---|
15 |
|
---|
16 | /* becomes */
|
---|
17 |
|
---|
18 | body {
|
---|
19 | background: rgba(153, 221, 153, 0.8);
|
---|
20 | }
|
---|
21 | ```
|
---|
22 |
|
---|
23 | ## Usage
|
---|
24 |
|
---|
25 | Add [PostCSS Color Hex Alpha] to your project:
|
---|
26 |
|
---|
27 | ```bash
|
---|
28 | npm install postcss-color-hex-alpha --save-dev
|
---|
29 | ```
|
---|
30 |
|
---|
31 | Use [PostCSS Color Hex Alpha] to process your CSS:
|
---|
32 |
|
---|
33 | ```js
|
---|
34 | const postcssColorHexAlpha = require('postcss-color-hex-alpha');
|
---|
35 |
|
---|
36 | postcssColorHexAlpha.process(YOUR_CSS /*, processOptions, pluginOptions */);
|
---|
37 | ```
|
---|
38 |
|
---|
39 | Or use it as a [PostCSS] plugin:
|
---|
40 |
|
---|
41 | ```js
|
---|
42 | const postcss = require('postcss');
|
---|
43 | const postcssColorHexAlpha = require('postcss-color-hex-alpha');
|
---|
44 |
|
---|
45 | postcss([
|
---|
46 | postcssColorHexAlpha(/* pluginOptions */)
|
---|
47 | ]).process(YOUR_CSS /*, processOptions */);
|
---|
48 | ```
|
---|
49 |
|
---|
50 | [PostCSS Color Hex Alpha] runs in all Node environments, with special instructions for:
|
---|
51 |
|
---|
52 | | [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) |
|
---|
53 | | --- | --- | --- | --- | --- | --- |
|
---|
54 |
|
---|
55 | ## Options
|
---|
56 |
|
---|
57 | ### preserve
|
---|
58 |
|
---|
59 | The `preserve` option determines whether 4 & 8 character hex color notation
|
---|
60 | should be preserved in their original form. By default, these are not preserved.
|
---|
61 |
|
---|
62 | ```js
|
---|
63 | postcssColorHexAlpha({
|
---|
64 | preserve: true
|
---|
65 | });
|
---|
66 | ```
|
---|
67 |
|
---|
68 | ```pcss
|
---|
69 | body {
|
---|
70 | background: #9d9c;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /* becomes */
|
---|
74 |
|
---|
75 | body {
|
---|
76 | background: rgba(153, 221, 153, 0.8);
|
---|
77 | background: #9d9c;
|
---|
78 | }
|
---|
79 | ```
|
---|
80 |
|
---|
81 | [cli-img]: https://img.shields.io/travis/postcss/postcss-color-hex-alpha.svg
|
---|
82 | [cli-url]: https://travis-ci.org/postcss/postcss-color-hex-alpha
|
---|
83 | [css-img]: https://cssdb.org/badge/hexadecimal-alpha-notation.svg
|
---|
84 | [css-url]: https://cssdb.org/#hexadecimal-alpha-notation
|
---|
85 | [git-img]: https://img.shields.io/badge/support-chat-blue.svg
|
---|
86 | [git-url]: https://gitter.im/postcss/postcss
|
---|
87 | [npm-img]: https://img.shields.io/npm/v/postcss-color-hex-alpha.svg
|
---|
88 | [npm-url]: https://www.npmjs.com/package/postcss-color-hex-alpha
|
---|
89 |
|
---|
90 | [PostCSS]: https://github.com/postcss/postcss
|
---|
91 | [PostCSS Color Hex Alpha]: https://github.com/postcss/postcss-color-hex-alpha
|
---|
92 | [CSS Color Module]: https://www.w3.org/TR/css-color-4/#hex-notation
|
---|