source: frontend/node_modules/postcss-dir-pseudo-class/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.3 KB
Line 
1# PostCSS Dir Pseudo Class [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" 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[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
7
8[PostCSS Dir Pseudo Class] lets you style by directionality using the `:dir()`
9pseudo-class in CSS, following the [Selectors] specification.
10
11[!['Can I use' table](https://caniuse.bitsofco.de/image/css-dir-pseudo.png)](https://caniuse.com/#feat=css-dir-pseudo)
12
13```pcss
14article h3:dir(rtl) {
15 margin-right: 10px;
16}
17
18article h3:dir(ltr) {
19 margin-left: 10px;
20}
21
22/* becomes */
23
24[dir="rtl"] article h3 {
25 margin-right: 10px;
26}
27
28[dir="ltr"] article h3 {
29 margin-left: 10px;
30}
31```
32
33### Maintaining Specificity
34
35Using [PostCSS Dir Pseudo Class] will not impact selector weight, but it will
36require having at least one `[dir]` attribute in your HTML. If you don’t have
37_any_ `[dir]` attributes, consider using the following JavaScript:
38
39```js
40// force at least one dir attribute (this can run at any time)
41document.documentElement.dir=document.documentElement.dir||'ltr';
42```
43
44If you absolutely cannot add a `[dir]` attribute in your HTML or even force one
45via JavaScript, you can still work around this by presuming a direction in your
46CSS using the [`dir` option](#dir-option), but understand that this will
47sometimes increase selector weight by one element (`html`).
48
49## Usage
50
51Add [PostCSS Dir Pseudo Class] to your project:
52
53```bash
54npm install postcss-dir-pseudo-class --save-dev
55```
56
57Use [PostCSS Dir Pseudo Class] to process your CSS:
58
59```js
60const postcssDirPseudoClass = require('postcss-dir-pseudo-class');
61
62postcssDirPseudoClass.process(YOUR_CSS /*, processOptions, pluginOptions */);
63```
64
65Or use it as a [PostCSS] plugin:
66
67```js
68const postcss = require('postcss');
69const postcssDirPseudoClass = require('postcss-dir-pseudo-class');
70
71postcss([
72 postcssDirPseudoClass(/* pluginOptions */)
73]).process(YOUR_CSS /*, processOptions */);
74```
75
76[PostCSS Dir Pseudo Class] runs in all Node environments, with special instructions for:
77
78| [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) |
79| --- | --- | --- | --- | --- | --- |
80
81## Options
82
83### dir
84
85The `dir` option allows you presume a direction in your CSS. By default, this
86is not specified and you are required to include a direction `[dir]` attribute
87somewhere in your HTML, preferably on the `html` element.
88
89Here’s an example of using the `dir` option to presume a left-to-right
90direction:
91
92```js
93postcssDirPseudoClass({ dir: 'ltr' });
94```
95
96```pcss
97.example:dir(ltr) {
98 margin-left: 10px;
99}
100
101.example:dir(rtl) {
102 margin-right: 10px;
103}
104
105/* becomes */
106
107html:not([dir="rtl"]) .example {
108 margin-left: 10px;
109}
110
111[dir="rtl"] .example {
112 margin-right: 10px;
113}
114```
115
116### preserve
117
118The `preserve` option determines whether the original `:dir()` rule should
119remain in the CSS. By default, the original rule is not preserved.
120
121```js
122postcssDirPseudoClass({ preserve: true });
123```
124
125```pcss
126article h3:dir(rtl) {
127 margin-right: 10px;
128}
129
130article h3:dir(ltr) {
131 margin-left: 10px;
132}
133
134/* becomes */
135
136[dir="rtl"] article h3 {
137 margin-right: 10px;
138}
139
140article h3:dir(rtl) {
141 margin-right: 10px;
142}
143
144[dir="ltr"] article h3 {
145 margin-left: 10px;
146}
147
148article h3:dir(ltr) {
149 margin-left: 10px;
150}
151```
152
153[cli-img]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml/badge.svg
154[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
155[css-img]: https://cssdb.org/images/badges/dir-pseudo-class.svg
156[css-url]: https://cssdb.org/#dir-pseudo-class
157[discord]: https://discord.gg/bUadyRwkJS
158[npm-img]: https://img.shields.io/npm/v/postcss-dir-pseudo-class.svg
159[npm-url]: https://www.npmjs.com/package/postcss-dir-pseudo-class
160
161[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
162[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
163[PostCSS]: https://github.com/postcss/postcss
164[PostCSS Loader]: https://github.com/postcss/postcss-loader
165[PostCSS Dir Pseudo Class]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class
166[Selectors]: https://www.w3.org/TR/selectors-4/#the-dir-pseudo
Note: See TracBrowser for help on using the repository browser.