Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 3d926c5

Browse files
committed
Update documentation
1 parent 0fcde20 commit 3d926c5

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

README.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,70 @@
1-
# PostCSS :dir() [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
1+
# PostCSS :dir() Pseudo [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
22

33
[![CSS Standard Status][css-img]][css-url]
44
[![NPM Version][npm-img]][npm-url]
55
[![Build Status][cli-img]][cli-url]
66
[![Licensing][lic-img]][lic-url]
77
[![Gitter Chat][git-img]][git-url]
88

9-
[PostCSS :dir()] lets you use the `:dir` pseudo-class in CSS, following the
10-
[Selectors] specification.
9+
[PostCSS :dir() Pseudo] lets you use the `:dir()` pseudo-class to style by
10+
directionality in CSS, following the [Selectors] specification.
1111

1212
```css
13-
.example:dir(rtl) {
13+
article h3:dir(rtl) {
1414
margin-right: 10px;
1515
}
1616

17-
.example:dir(ltr) {
17+
article h3:dir(ltr) {
1818
margin-left: 10px;
1919
}
2020

2121
/* becomes */
2222

23-
[dir="rtl"] .example {
23+
[dir="rtl"] article h3 {
2424
margin-right: 10px;
2525
}
2626

27-
[dir="ltr"] .example {
27+
[dir="ltr"] article h3 {
2828
margin-left: 10px;
2929
}
3030
```
3131

32-
If your [browserslist] already supports the `:dir` pseudo-class, this plugin
33-
will not change your CSS. You can learn more this by reading about the
34-
[`browsers` option](#browsers-option).
32+
### Future-proof your CSS
3533

36-
[PostCSS :dir()] does not change selector weight, but does require at least one
37-
`[dir]` attribute in your HTML. If you don’t have _any_ `[dir]` attributes,
38-
consider using the following JavaScript:
34+
If your [browserslist] already supports the `:dir()` pseudo-class, this plugin
35+
will not change your CSS. Learn more about this feature in the
36+
[`browsers`](#browsers-option) section.
37+
38+
### Maintain Specificity
39+
40+
Using [PostCSS :dir() Pseudo] will not impact selector weight, but it will
41+
require having at least one `[dir]` attribute in your HTML. If you don’t have
42+
_any_ `[dir]` attributes, consider using the following JavaScript:
3943

4044
```js
4145
// force at least one dir attribute (this can run at any time)
4246
document.documentElement.dir=document.documentElement.dir||'ltr';
4347
```
4448

45-
If you absolutely cannot add a `[dir]` attribute in your HTML or force one via
46-
JavaScript, you can still get around this by presuming a direction in your CSS
47-
using the [`dir` option](#dir-option), but know that this will increase
48-
selector weight by one element (`html`).
49+
If you absolutely cannot add a `[dir]` attribute in your HTML or even force one
50+
via JavaScript, you can still work around this by presuming a direction in your
51+
CSS using the [`dir` option](#dir-option), but understand that this will
52+
sometimes increase selector weight by one element (`html`).
4953

5054
## Usage
5155

52-
Add [PostCSS :dir()] to your build tool:
56+
Add [PostCSS :dir() Pseudo] to your build tool:
5357

5458
```bash
5559
npm install postcss-dir-pseudo-class --save-dev
5660
```
5761

5862
#### Node
5963

60-
Use [PostCSS :dir()] to process your CSS:
64+
Use [PostCSS :dir() Pseudo] to process your CSS:
6165

6266
```js
63-
require('postcss-dir-pseudo-class').process(YOUR_CSS);
67+
require('postcss-dir-pseudo-class').process(YOUR_CSS /*, processConfig, options */);
6468
```
6569

6670
#### PostCSS
@@ -71,11 +75,11 @@ Add [PostCSS] to your build tool:
7175
npm install postcss --save-dev
7276
```
7377

74-
Use [PostCSS :dir()] as a plugin:
78+
Use [PostCSS :dir() Pseudo] as a plugin:
7579

7680
```js
7781
postcss([
78-
require('postcss-dir-pseudo-class')()
82+
require('postcss-dir-pseudo-class')(/* Options */)
7983
]).process(YOUR_CSS);
8084
```
8185

@@ -87,15 +91,15 @@ Add [Gulp PostCSS] to your build tool:
8791
npm install gulp-postcss --save-dev
8892
```
8993

90-
Use [PostCSS :dir()] in your Gulpfile:
94+
Use [PostCSS :dir() Pseudo] in your Gulpfile:
9195

9296
```js
9397
var postcss = require('gulp-postcss');
9498

9599
gulp.task('css', function () {
96100
return gulp.src('./src/*.css').pipe(
97101
postcss([
98-
require('postcss-dir-pseudo-class')()
102+
require('postcss-dir-pseudo-class')(/* Options */)
99103
])
100104
).pipe(
101105
gulp.dest('.')
@@ -111,7 +115,7 @@ Add [Grunt PostCSS] to your build tool:
111115
npm install grunt-postcss --save-dev
112116
```
113117

114-
Use [PostCSS :dir()] in your Gruntfile:
118+
Use [PostCSS :dir() Pseudo] in your Gruntfile:
115119

116120
```js
117121
grunt.loadNpmTasks('grunt-postcss');
@@ -120,7 +124,7 @@ grunt.initConfig({
120124
postcss: {
121125
options: {
122126
use: [
123-
require('postcss-dir-pseudo-class')()
127+
require('postcss-dir-pseudo-class')(/* Options */)
124128
]
125129
},
126130
dist: {
@@ -132,7 +136,7 @@ grunt.initConfig({
132136

133137
---
134138

135-
## browsers option
139+
## Browsers Option
136140

137141
If your [browserslist] already supports the `:dir` pseudo-class, this plugin
138142
will not change your CSS. While only Firefox currently supports `:dir`, this
@@ -170,9 +174,9 @@ In both of these examples, the CSS would remain unchanged.
170174
}
171175
```
172176

173-
## dir option
177+
## Dir Option
174178

175-
By default, this plugin requires you to specify a direction `[dir]` attribute
179+
By default, this plugin requires you to include a direction `[dir]` attribute
176180
in your HTML, preferably on the `html` element. If you prefer not to, you
177181
can presume a direction in your CSS using the `dir` option.
178182

@@ -196,7 +200,7 @@ require('postcss-dir-pseudo-class')({
196200

197201
/* becomes */
198202

199-
:not([dir="rtl"]) .example {
203+
html:not([dir="rtl"]) .example {
200204
margin-left: 10px;
201205
}
202206

@@ -205,9 +209,6 @@ require('postcss-dir-pseudo-class')({
205209
}
206210
```
207211

208-
*Note: The `:root` pseudo-class is added here to preserve the weight of the
209-
original selector.*
210-
211212
[cli-url]: https://travis-ci.org/jonathantneal/postcss-dir-pseudo-class
212213
[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-dir-pseudo-class.svg
213214
[css-img]: https://jonathantneal.github.io/css-db/badge/selectors-the-dir-pseudo.svg
@@ -223,5 +224,5 @@ original selector.*
223224
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
224225
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
225226
[PostCSS]: https://github.com/postcss/postcss
226-
[PostCSS :dir()]: https://github.com/jonathantneal/postcss-dir-pseudo-class
227+
[PostCSS :dir() Pseudo]: https://github.com/jonathantneal/postcss-dir-pseudo-class
227228
[Selectors]: https://drafts.csswg.org/selectors-4/#the-dir-pseudo

0 commit comments

Comments
 (0)