88[ PostCSS : dir ()] lets you use the ` :dir ` pseudo-class in CSS.
99
1010``` css
11- .example :dir (ltr ) {
12- margin-left : 10px ;
11+ .example :dir (rtl ) {
12+ margin-right : 10px ;
1313}
1414
1515/* becomes */
1616
17- [dir = " ltr " ] .example {
18- margin-left : 10px ;
17+ [dir = " rtl " ] .example {
18+ margin-right : 10px ;
1919}
2020```
2121
22- Selector weight remains the same, but this requires you to specify a direction
23- (` dir ` ) attribute in your HTML.
22+ If your [ browserslist] already supports the ` :dir ` pseudo-class, this plugin
23+ will not change your CSS. You can learn more this by reading about the
24+ [ ` browsers ` option] ( #browsers-option ) .
25+
26+ By default, this plugin requires you to specify a direction ` [dir] ` attribute
27+ in your HTML, preferably on the ` html ` element. If you prefer not to, you
28+ can presume a direction in your CSS using the [ ` dir ` option] ( #dir-option ) .
2429
2530## Usage
2631
@@ -105,6 +110,84 @@ grunt.initConfig({
105110});
106111```
107112
113+ ---
114+
115+ ## browsers option
116+
117+ If your [ browserslist] already supports the ` :dir ` pseudo-class, this plugin
118+ will not change your CSS. While only Firefox currently supports ` :dir ` , this
119+ will surely improve over time.
120+
121+ Here’s an example of a ` package.json ` using a browserslist that would fully
122+ support the ` :dir ` pseudo-class:
123+
124+ ``` json
125+ {
126+ "browserslist" : " firefox >= 49"
127+ }
128+ ```
129+
130+ And here’s an example of using the ` browsers ` option to accomplish the same
131+ thing:
132+
133+ ``` js
134+ require (' postcss-dir-pseudo-class' )({
135+ browsers: ' firefox >= 49'
136+ });
137+ ```
138+
139+ In both of these examples, the CSS would remain unchanged.
140+
141+ ``` css
142+ .example :dir (rtl ) {
143+ margin-right : 10px ;
144+ }
145+
146+ /* becomes */
147+
148+ .example :dir (rtl ) {
149+ margin-right : 10px ;
150+ }
151+ ```
152+
153+ ## dir option
154+
155+ By default, this plugin requires you to specify a direction ` [dir] ` attribute
156+ in your HTML, preferably on the ` html ` element. If you prefer not to, you
157+ can presume a direction in your CSS using the ` dir ` option.
158+
159+ Here’s an example of using the ` dir ` option to presume a left-to-right
160+ direction:
161+
162+ ``` js
163+ require (' postcss-dir-pseudo-class' )({
164+ dir: ' ltr'
165+ });
166+ ```
167+
168+ ``` css
169+ .example :dir (ltr ) {
170+ margin-left : 10px ;
171+ }
172+
173+ .example :dir (rtl ) {
174+ margin-right : 10px ;
175+ }
176+
177+ /* becomes */
178+
179+ :root .example {
180+ margin-left : 10px ;
181+ }
182+
183+ [dir = " rtl" ] .example {
184+ margin-right : 10px ;
185+ }
186+ ```
187+
188+ * Note: The ` :root ` pseudo-class is added here to preserve the weight of the
189+ original selector.*
190+
108191[ npm-url ] : https://www.npmjs.com/package/postcss-dir-pseudo-class
109192[ npm-img ] : https://img.shields.io/npm/v/postcss-dir-pseudo-class.svg
110193[ cli-url ] : https://travis-ci.org/jonathantneal/postcss-dir-pseudo-class
@@ -118,3 +201,4 @@ grunt.initConfig({
118201[ PostCSS ] : https://github.com/postcss/postcss
119202[ Gulp PostCSS ] : https://github.com/postcss/gulp-postcss
120203[ Grunt PostCSS ] : https://github.com/nDmitry/grunt-postcss
204+ [ browserslist ] : https://github.com/ai/browserslist
0 commit comments