autoprefixer 9.3.1 → 9.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +501 -89
- package/lib/at-rule.js +2 -2
- package/lib/browsers.js +6 -6
- package/lib/declaration.js +26 -26
- package/lib/hacks/align-content.js +4 -4
- package/lib/hacks/align-items.js +4 -4
- package/lib/hacks/align-self.js +14 -8
- package/lib/hacks/block-logical.js +2 -2
- package/lib/hacks/border-radius.js +2 -2
- package/lib/hacks/break-props.js +6 -6
- package/lib/hacks/color-adjust.js +2 -2
- package/lib/hacks/display-flex.js +6 -6
- package/lib/hacks/flex-basis.js +4 -4
- package/lib/hacks/flex-direction.js +4 -4
- package/lib/hacks/flex-grow.js +2 -2
- package/lib/hacks/flex-shrink.js +4 -4
- package/lib/hacks/flex.js +4 -4
- package/lib/hacks/gradient.js +32 -32
- package/lib/hacks/grid-column-align.js +4 -4
- package/lib/hacks/grid-row-align.js +4 -4
- package/lib/hacks/grid-rows-columns.js +93 -11
- package/lib/hacks/grid-start.js +4 -4
- package/lib/hacks/grid-template-areas.js +14 -62
- package/lib/hacks/grid-utils.js +129 -3
- package/lib/hacks/image-rendering.js +8 -8
- package/lib/hacks/inline-logical.js +2 -2
- package/lib/hacks/justify-content.js +4 -4
- package/lib/hacks/mask-border.js +2 -2
- package/lib/hacks/order.js +4 -4
- package/lib/hacks/overscroll-behavior.js +4 -4
- package/lib/hacks/pixelated.js +2 -2
- package/lib/hacks/placeholder.js +2 -2
- package/lib/hacks/transform-decl.js +6 -6
- package/lib/old-selector.js +2 -2
- package/lib/prefixer.js +8 -8
- package/lib/prefixes.js +18 -18
- package/lib/processor.js +88 -21
- package/lib/resolution.js +6 -6
- package/lib/selector.js +16 -16
- package/lib/supports.js +30 -30
- package/lib/transition.js +22 -22
- package/lib/value.js +12 -12
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
title="Autoprefixer logo by Anton Lovchikov">
|
|
6
6
|
|
|
7
7
|
[PostCSS] plugin to parse CSS and add vendor prefixes to CSS rules using values
|
|
8
|
-
from [Can I Use]. It is [recommended] by Google and used in Twitter and
|
|
8
|
+
from [Can I Use]. It is [recommended] by Google and used in Twitter and Alibaba.
|
|
9
9
|
|
|
10
10
|
Write your CSS rules without vendor prefixes (in fact, forget about them
|
|
11
11
|
entirely):
|
|
@@ -41,15 +41,42 @@ Twitter account for news and releases: [@autoprefixer].
|
|
|
41
41
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
|
|
42
42
|
</a>
|
|
43
43
|
|
|
44
|
-
[interactive demo]:
|
|
44
|
+
[interactive demo]: https://autoprefixer.github.io/
|
|
45
45
|
[@autoprefixer]: https://twitter.com/autoprefixer
|
|
46
46
|
[recommended]: https://developers.google.com/web/tools/setup/setup-buildtools#dont_trip_up_with_vendor_prefixes
|
|
47
|
-
[Can I Use]:
|
|
47
|
+
[Can I Use]: https://caniuse.com/
|
|
48
48
|
[cult-img]: http://cultofmartians.com/assets/badges/badge.svg
|
|
49
49
|
[PostCSS]: https://github.com/postcss/postcss
|
|
50
50
|
[cult]: http://cultofmartians.com/tasks/autoprefixer-grid.html
|
|
51
51
|
|
|
52
52
|
|
|
53
|
+
## Contents
|
|
54
|
+
|
|
55
|
+
- [Browsers](#browsers)
|
|
56
|
+
- [FAQ](#faq)
|
|
57
|
+
- [Does Autoprefixer polyfill Grid Layout for IE?](#does-autoprefixer-polyfill-grid-layout-for-ie)
|
|
58
|
+
- [No prefixes in production](#no-prefixes-in-production)
|
|
59
|
+
- [What is the unprefixed version of `-webkit-min-device-pixel-ratio`?](#what-is-the-unprefixed-version-of--webkit-min-device-pixel-ratio)
|
|
60
|
+
- [Does it add polyfills?](#does-it-add-polyfills)
|
|
61
|
+
- [Why doesn’t Autoprefixer add prefixes to `border-radius`?](#why-doesnt-autoprefixer-add-prefixes-to-border-radius)
|
|
62
|
+
- [Why does Autoprefixer use unprefixed properties in `@-webkit-keyframes`?](#why-does-autoprefixer-use-unprefixed-properties-in--webkit-keyframes)
|
|
63
|
+
- [How to work with legacy `-webkit-` only code?](#how-to-work-with-legacy--webkit--only-code)
|
|
64
|
+
- [Does Autoprefixer add `-epub-` prefix?](#does-autoprefixer-add--epub--prefix)
|
|
65
|
+
- [Why doesn’t Autoprefixer transform generic font-family `system-ui`?](#why-doesnt-autoprefixer-transform-generic-font-family-system-ui)
|
|
66
|
+
- [Usage](#usage)
|
|
67
|
+
- [Gulp](#gulp)
|
|
68
|
+
- [Webpack](#webpack)
|
|
69
|
+
- [CSS-in-JS](#css-in-js)
|
|
70
|
+
- [CLI](#cli)
|
|
71
|
+
- [Other Build Tools](#other-build-tools)
|
|
72
|
+
- [JavaScript](#javascript)
|
|
73
|
+
- [Text Editors and IDE](#text-editors-and-ide)
|
|
74
|
+
- [Warnings](#warnings)
|
|
75
|
+
- [Disabling](#disabling)
|
|
76
|
+
- [Options](#options)
|
|
77
|
+
- [Grid Autoplacement support in IE](#grid-autoplacement-support-in-ie)
|
|
78
|
+
- [Debug](#debug)
|
|
79
|
+
|
|
53
80
|
## Browsers
|
|
54
81
|
|
|
55
82
|
Autoprefixer uses [Browserslist], so you can specify the browsers
|
|
@@ -69,25 +96,25 @@ See [Browserslist docs] for queries, browser names, config format, and defaults.
|
|
|
69
96
|
[babel-preset-env]: https://github.com/babel/babel/tree/master/packages/babel-preset-env
|
|
70
97
|
[Best Practices]: https://github.com/browserslist/browserslist#best-practices
|
|
71
98
|
[Browserslist]: https://github.com/ai/browserslist
|
|
72
|
-
[Stylelint]:
|
|
99
|
+
[Stylelint]: https://stylelint.io/
|
|
73
100
|
|
|
74
101
|
|
|
75
102
|
## FAQ
|
|
76
103
|
|
|
77
|
-
|
|
104
|
+
### Does Autoprefixer polyfill Grid Layout for IE?
|
|
78
105
|
|
|
79
|
-
Autoprefixer can be used to
|
|
80
|
-
polyfill will not work in 100% of cases. This is why it is disabled by default.
|
|
106
|
+
Autoprefixer can be used to translate modern CSS Grid syntax into IE 10 and IE 11 syntax,
|
|
107
|
+
but this polyfill will not work in 100% of cases. This is why it is disabled by default.
|
|
81
108
|
|
|
82
|
-
First, you need to enable Grid prefixes by `grid:
|
|
109
|
+
First, you need to enable Grid prefixes by using either the `grid: "autoplace"` option or the `/* autoprefixer grid: autoplace */` control comment.
|
|
83
110
|
|
|
84
111
|
Second, you need to test every fix with Grid in IE. It is not an enable and
|
|
85
112
|
forget feature, but it is still very useful.
|
|
86
113
|
Financial Times and Yandex use it in production.
|
|
87
114
|
|
|
88
|
-
Third, there is
|
|
89
|
-
|
|
90
|
-
|
|
115
|
+
Third, there is only very limited auto placement support. Read the [Grid Autoplacement support in IE](#grid-autoplacement-support-in-ie) section for more details.
|
|
116
|
+
|
|
117
|
+
Fourth, if you are not using the autoplacement feature, the best way to use Autoprefixer is by using `grid-template` or `grid-template-areas`.
|
|
91
118
|
|
|
92
119
|
```css
|
|
93
120
|
.page {
|
|
@@ -119,13 +146,13 @@ See also:
|
|
|
119
146
|
* [`postcss-gap-properties`] to use new `gap` property
|
|
120
147
|
instead of old `grid-gap`.
|
|
121
148
|
* [`postcss-grid-kiss`] has alternate “everything in one property” syntax,
|
|
122
|
-
which
|
|
149
|
+
which makes using Autoprefixer’s Grid translations safer.
|
|
123
150
|
|
|
124
151
|
[The guide about Grids in IE and Autoprefixer]: https://css-tricks.com/css-grid-in-ie-css-grid-and-the-new-autoprefixer/
|
|
125
152
|
[`postcss-gap-properties`]: https://github.com/jonathantneal/postcss-gap-properties
|
|
126
153
|
[`postcss-grid-kiss`]: https://github.com/sylvainpolletvillard/postcss-grid-kiss
|
|
127
154
|
|
|
128
|
-
|
|
155
|
+
### No prefixes in production
|
|
129
156
|
|
|
130
157
|
Many other tools contain Autoprefixer. For example, webpack uses Autoprefixer
|
|
131
158
|
to minify CSS by cleaning unnecessary prefixes.
|
|
@@ -141,7 +168,7 @@ cssnano, doiuse, cssnext, etc) use the same browsers list.
|
|
|
141
168
|
[browserslist config file]: https://github.com/ai/browserslist#config-file
|
|
142
169
|
|
|
143
170
|
|
|
144
|
-
|
|
171
|
+
### What is the unprefixed version of `-webkit-min-device-pixel-ratio`?
|
|
145
172
|
|
|
146
173
|
```css
|
|
147
174
|
@media (min-resolution: 2dppx) {
|
|
@@ -164,7 +191,7 @@ Will be compiled to:
|
|
|
164
191
|
```
|
|
165
192
|
|
|
166
193
|
|
|
167
|
-
|
|
194
|
+
### Does it add polyfills?
|
|
168
195
|
|
|
169
196
|
No. Autoprefixer only adds prefixes.
|
|
170
197
|
|
|
@@ -185,22 +212,22 @@ you might take a look at:
|
|
|
185
212
|
[Oldie]: https://github.com/jonathantneal/oldie
|
|
186
213
|
|
|
187
214
|
|
|
188
|
-
|
|
215
|
+
### Why doesn’t Autoprefixer add prefixes to `border-radius`?
|
|
189
216
|
|
|
190
217
|
Developers are often surprised by how few prefixes are required today.
|
|
191
218
|
If Autoprefixer doesn’t add prefixes to your CSS, check if they’re still
|
|
192
219
|
required on [Can I Use].
|
|
193
220
|
|
|
194
|
-
[Can I Use]:
|
|
221
|
+
[Can I Use]: https://caniuse.com/
|
|
195
222
|
|
|
196
223
|
|
|
197
|
-
|
|
224
|
+
### Why does Autoprefixer use unprefixed properties in `@-webkit-keyframes`?
|
|
198
225
|
|
|
199
226
|
Browser teams can remove some prefixes before others, so we try to use all
|
|
200
227
|
combinations of prefixed/unprefixed values.
|
|
201
228
|
|
|
202
229
|
|
|
203
|
-
|
|
230
|
+
### How to work with legacy `-webkit-` only code?
|
|
204
231
|
|
|
205
232
|
Autoprefixer needs unprefixed property to add prefixes. So if you only
|
|
206
233
|
wrote `-webkit-gradient` without W3C’s `gradient`,
|
|
@@ -212,7 +239,7 @@ Use [postcss-unprefix] before Autoprefixer.
|
|
|
212
239
|
[postcss-unprefix]: https://github.com/gucong3000/postcss-unprefix
|
|
213
240
|
|
|
214
241
|
|
|
215
|
-
|
|
242
|
+
### Does Autoprefixer add `-epub-` prefix?
|
|
216
243
|
|
|
217
244
|
No, Autoprefixer works only with browsers prefixes from Can I Use.
|
|
218
245
|
But you can use [postcss-epub]
|
|
@@ -221,7 +248,7 @@ for prefixing ePub3 properties.
|
|
|
221
248
|
[postcss-epub]: https://github.com/Rycochet/postcss-epub
|
|
222
249
|
|
|
223
250
|
|
|
224
|
-
|
|
251
|
+
### Why doesn’t Autoprefixer transform generic font-family `system-ui`?
|
|
225
252
|
|
|
226
253
|
`system-ui` is technically not a prefix and the transformation is not
|
|
227
254
|
future-proof. You can use [postcss-font-family-system-ui] to transform
|
|
@@ -290,41 +317,58 @@ module.exports = {
|
|
|
290
317
|
[webpack]: http://webpack.github.io/
|
|
291
318
|
|
|
292
319
|
|
|
293
|
-
###
|
|
320
|
+
### CSS-in-JS
|
|
294
321
|
|
|
295
|
-
|
|
322
|
+
The best way to use PostCSS with CSS-in-JS is [`astroturf`].
|
|
323
|
+
Add it’s loader to your `webpack.config.js`:
|
|
296
324
|
|
|
297
325
|
```js
|
|
298
|
-
module.exports =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
});
|
|
326
|
+
module.exports = {
|
|
327
|
+
module: {
|
|
328
|
+
rules: [
|
|
329
|
+
{
|
|
330
|
+
test: /\.css$/,
|
|
331
|
+
use: ['style-loader', 'postcss-loader'],
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
test: /\.jsx?$/,
|
|
335
|
+
use: ['babel-loader', 'astroturf/loader'],
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
```
|
|
314
341
|
|
|
315
|
-
|
|
316
|
-
|
|
342
|
+
Then create `postcss.config.js`:
|
|
343
|
+
|
|
344
|
+
```js
|
|
345
|
+
module.exports = {
|
|
346
|
+
plugins: [
|
|
347
|
+
require('autoprefixer')
|
|
348
|
+
]
|
|
349
|
+
}
|
|
317
350
|
```
|
|
318
351
|
|
|
319
|
-
|
|
320
|
-
with [other PostCSS plugins].
|
|
352
|
+
[`astroturf`]: https://github.com/4Catalyzer/astroturf
|
|
321
353
|
|
|
322
|
-
|
|
323
|
-
|
|
354
|
+
|
|
355
|
+
### CLI
|
|
356
|
+
|
|
357
|
+
You can use the [postcss-cli] to run Autoprefixer from CLI:
|
|
358
|
+
|
|
359
|
+
```sh
|
|
360
|
+
npm install postcss-cli autoprefixer
|
|
361
|
+
npx postcss *.css --use autoprefixer -d build/
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
See `postcss -h` for help.
|
|
365
|
+
|
|
366
|
+
[postcss-cli]: https://github.com/postcss/postcss-cli
|
|
324
367
|
|
|
325
368
|
|
|
326
|
-
### Other Build Tools
|
|
369
|
+
### Other Build Tools
|
|
327
370
|
|
|
371
|
+
* **Grunt:** [grunt-postcss]
|
|
328
372
|
* **Ruby on Rails**: [autoprefixer-rails]
|
|
329
373
|
* **Neutrino**: [neutrino-middleware-postcss]
|
|
330
374
|
* **Jekyll**: add `autoprefixer-rails` and `jekyll-assets` to `Gemfile`
|
|
@@ -339,9 +383,10 @@ with [other PostCSS plugins].
|
|
|
339
383
|
[autoprefixer-rails]: https://github.com/ai/autoprefixer-rails
|
|
340
384
|
[broccoli-postcss]: https://github.com/jeffjewiss/broccoli-postcss
|
|
341
385
|
[postcss-brunch]: https://github.com/iamvdo/postcss-brunch
|
|
386
|
+
[grunt-postcss]: https://github.com/nDmitry/grunt-postcss
|
|
342
387
|
|
|
343
388
|
|
|
344
|
-
|
|
389
|
+
#### Preprocessors
|
|
345
390
|
|
|
346
391
|
* **Less**: [less-plugin-autoprefix]
|
|
347
392
|
* **Stylus**: [autoprefixer-stylus]
|
|
@@ -352,42 +397,12 @@ with [other PostCSS plugins].
|
|
|
352
397
|
[autoprefixer-rails#compass]: https://github.com/ai/autoprefixer-rails#compass
|
|
353
398
|
|
|
354
399
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
There is [postcss-js] to use Autoprefixer in React Inline Styles, [Free Style],
|
|
358
|
-
Radium and other CSS-in-JS solutions.
|
|
359
|
-
|
|
360
|
-
```js
|
|
361
|
-
let prefixer = postcssJs.sync([ autoprefixer ]);
|
|
362
|
-
let style = prefixer({
|
|
363
|
-
display: 'flex'
|
|
364
|
-
});
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
[postcss-js]: https://github.com/postcss/postcss-js
|
|
368
|
-
[Free Style]: https://github.com/blakeembrey/free-style
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
### GUI Tools
|
|
400
|
+
#### GUI Tools
|
|
372
401
|
|
|
373
402
|
* [CodeKit](https://codekitapp.com/help/autoprefixer/)
|
|
374
403
|
* [Prepros](https://prepros.io)
|
|
375
404
|
|
|
376
405
|
|
|
377
|
-
### CLI
|
|
378
|
-
|
|
379
|
-
You can use the [postcss-cli] to run Autoprefixer from CLI:
|
|
380
|
-
|
|
381
|
-
```sh
|
|
382
|
-
npm install postcss-cli autoprefixer
|
|
383
|
-
npx postcss *.css --use autoprefixer -d build/
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
See `postcss -h` for help.
|
|
387
|
-
|
|
388
|
-
[postcss-cli]: https://github.com/postcss/postcss-cli
|
|
389
|
-
|
|
390
|
-
|
|
391
406
|
### JavaScript
|
|
392
407
|
|
|
393
408
|
You can use Autoprefixer with [PostCSS] in your Node.js application
|
|
@@ -431,7 +446,7 @@ If you can’t move to a build tool, you can use text editor plugins:
|
|
|
431
446
|
* [Atom Editor](https://github.com/sindresorhus/atom-autoprefixer)
|
|
432
447
|
* [Visual Studio](https://github.com/madskristensen/WebCompiler)
|
|
433
448
|
|
|
434
|
-
[Gulp]:
|
|
449
|
+
[Gulp]: https://gulpjs.com/
|
|
435
450
|
|
|
436
451
|
|
|
437
452
|
## Warnings
|
|
@@ -478,19 +493,20 @@ If some prefixes were generated incorrectly, please create an [issue on GitHub].
|
|
|
478
493
|
|
|
479
494
|
### Features
|
|
480
495
|
|
|
481
|
-
You can use these plugin options to
|
|
496
|
+
You can use these plugin options to control some of Autoprefixer’s features.
|
|
482
497
|
|
|
483
|
-
* `grid:
|
|
498
|
+
* `grid: "autoplace"` will enable `-ms-` prefixes for Grid Layout including some
|
|
499
|
+
[limited autoplacement support](#grid-autoplacement-support-in-ie).
|
|
484
500
|
* `supports: false` will disable `@supports` parameters prefixing.
|
|
485
501
|
* `flexbox: false` will disable flexbox properties prefixing.
|
|
486
502
|
Or `flexbox: "no-2009"` will add prefixes only for final and IE
|
|
487
503
|
versions of specification.
|
|
488
504
|
* `remove: false` will disable cleaning outdated prefixes.
|
|
489
505
|
|
|
490
|
-
You should set them
|
|
506
|
+
You should set them inside the plugin like so:
|
|
491
507
|
|
|
492
508
|
```js
|
|
493
|
-
autoprefixer({ grid:
|
|
509
|
+
autoprefixer({ grid: "autoplace" });
|
|
494
510
|
```
|
|
495
511
|
|
|
496
512
|
|
|
@@ -518,10 +534,16 @@ you can use control comments to disable Autoprefixer.
|
|
|
518
534
|
|
|
519
535
|
There are three types of control comments:
|
|
520
536
|
|
|
521
|
-
* `/* autoprefixer: off
|
|
522
|
-
|
|
537
|
+
* `/* autoprefixer: (on|off) */`: enable/disable all Autoprefixer translations for the
|
|
538
|
+
whole block both *before* and *after* the comment.
|
|
539
|
+
* `/* autoprefixer: ignore next */`: disable Autoprefixer only for the next property
|
|
523
540
|
or next rule selector or at-rule parameters (but not rule/at‑rule body).
|
|
524
|
-
* `/* autoprefixer grid:
|
|
541
|
+
* `/* autoprefixer grid: (autoplace|no-autoplace|off) */`: control how Autoprefixer handles
|
|
542
|
+
grid translations for the whole block:
|
|
543
|
+
* `autoplace`: enable grid translations with autoplacement support.
|
|
544
|
+
* `no-autoplace`: enable grid translations with autoplacement support *disabled*.
|
|
545
|
+
(alias for deprecated value `on`)
|
|
546
|
+
* `off`: disable all grid translations.
|
|
525
547
|
|
|
526
548
|
You can also use comments recursively:
|
|
527
549
|
|
|
@@ -535,6 +557,20 @@ You can also use comments recursively:
|
|
|
535
557
|
}
|
|
536
558
|
```
|
|
537
559
|
|
|
560
|
+
Note that comments that disable the whole block should not be featured in the same
|
|
561
|
+
block twice:
|
|
562
|
+
|
|
563
|
+
```css
|
|
564
|
+
/* How not to use block level control comments */
|
|
565
|
+
|
|
566
|
+
.do-not-do-this {
|
|
567
|
+
/* autoprefixer: off */
|
|
568
|
+
transition: 1s;
|
|
569
|
+
/* autoprefixer: on */
|
|
570
|
+
transform: rotate(20deg);
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
538
574
|
|
|
539
575
|
## Options
|
|
540
576
|
|
|
@@ -558,9 +594,14 @@ Available options are:
|
|
|
558
594
|
* `flexbox` (boolean|string): should Autoprefixer add prefixes for flexbox
|
|
559
595
|
properties. With `"no-2009"` value Autoprefixer will add prefixes only
|
|
560
596
|
for final and IE versions of specification. Default is `true`.
|
|
561
|
-
* `grid` (
|
|
562
|
-
properties
|
|
563
|
-
|
|
597
|
+
* `grid` (false|"autoplace"|"no-autoplace"): should Autoprefixer add IE prefixes for Grid Layout
|
|
598
|
+
properties?
|
|
599
|
+
* `false` (default): prevent Autoprefixer from outputting CSS Grid translations.
|
|
600
|
+
* `"autoplace"`: enable Autoprefixer grid translations and *include* autoplacement
|
|
601
|
+
support. You can also use `/* autoprefixer grid: autoplace */` in your CSS.
|
|
602
|
+
* `"no-autoplace"`: enable Autoprefixer grid translations but *exclude* autoplacement
|
|
603
|
+
support. You can also use `/* autoprefixer grid: no-autoplace */` in your CSS.
|
|
604
|
+
(alias for the deprecated `true` value)
|
|
564
605
|
* `stats` (object): custom [usage statistics] for `> 10% in my stats`
|
|
565
606
|
browsers query.
|
|
566
607
|
* `browsers` (array): list of queries for target browsers. Try to not use it.
|
|
@@ -579,6 +620,377 @@ to increase performance.
|
|
|
579
620
|
[usage statistics]: https://github.com/ai/browserslist#custom-usage-data
|
|
580
621
|
[PostCSS API]: http://api.postcss.org
|
|
581
622
|
|
|
623
|
+
## Grid Autoplacement support in IE
|
|
624
|
+
|
|
625
|
+
If the `grid` option is set to `"autoplace"`, limited autoplacement support is added to Autoprefixers grid translations. You can also use the `/* autoprefixer grid: autoplace */` control comment to enable autoplacement
|
|
626
|
+
|
|
627
|
+
Autoprefixer will only autoplace grid cells if both `grid-template-rows` and `grid-template-columns` has been set. If `grid-template` or `grid-template-areas` has been set, Autoprefixer will use area based cell placement instead.
|
|
628
|
+
|
|
629
|
+
Autoprefixer supports autoplacement by using `nth-child` CSS selectors. It creates [number of columns] x [number of rows] `nth-child` selectors. For this reason Autoplacement is only supported within the explicit grid.
|
|
630
|
+
|
|
631
|
+
```css
|
|
632
|
+
/* Input CSS */
|
|
633
|
+
|
|
634
|
+
/* autoprefixer grid: autoplace */
|
|
635
|
+
|
|
636
|
+
.autoplacement-example {
|
|
637
|
+
display: grid;
|
|
638
|
+
grid-template-columns: 1fr 1fr;
|
|
639
|
+
grid-template-rows: auto auto;
|
|
640
|
+
grid-gap: 20px;
|
|
641
|
+
}
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
```css
|
|
645
|
+
/* Output CSS */
|
|
646
|
+
|
|
647
|
+
/* autoprefixer grid: autoplace */
|
|
648
|
+
|
|
649
|
+
.autoplacement-example {
|
|
650
|
+
display: -ms-grid;
|
|
651
|
+
display: grid;
|
|
652
|
+
-ms-grid-columns: 1fr 20px 1fr;
|
|
653
|
+
grid-template-columns: 1fr 1fr;
|
|
654
|
+
-ms-grid-rows: auto 20px auto;
|
|
655
|
+
grid-template-rows: auto auto;
|
|
656
|
+
grid-gap: 20px;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
.autoplacement-example > *:nth-child(1) {
|
|
660
|
+
-ms-grid-row: 1;
|
|
661
|
+
-ms-grid-column: 1;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
.autoplacement-example > *:nth-child(2) {
|
|
665
|
+
-ms-grid-row: 1;
|
|
666
|
+
-ms-grid-column: 3;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
.autoplacement-example > *:nth-child(3) {
|
|
670
|
+
-ms-grid-row: 3;
|
|
671
|
+
-ms-grid-column: 1;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
.autoplacement-example > *:nth-child(4) {
|
|
675
|
+
-ms-grid-row: 3;
|
|
676
|
+
-ms-grid-column: 3;
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
### Beware of enabling autoplacement in old projects
|
|
681
|
+
|
|
682
|
+
Be careful about enabling autoplacement in any already established projects that have
|
|
683
|
+
previously not used Autoprefixer's grid autoplacement feature before.
|
|
684
|
+
|
|
685
|
+
If this was your html:
|
|
686
|
+
|
|
687
|
+
```html
|
|
688
|
+
<div class="grid">
|
|
689
|
+
<div class="grid-cell"></div>
|
|
690
|
+
</div>
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
The following CSS will not work as expected with the autoplacement feature enabled:
|
|
694
|
+
|
|
695
|
+
```css
|
|
696
|
+
/* Unsafe CSS when Autoplacement is enabled */
|
|
697
|
+
|
|
698
|
+
.grid-cell {
|
|
699
|
+
grid-column: 2;
|
|
700
|
+
grid-row: 2;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
.grid {
|
|
704
|
+
display: grid;
|
|
705
|
+
grid-template-columns: repeat(3, 1fr);
|
|
706
|
+
grid-template-rows: repeat(3, 1fr);
|
|
707
|
+
}
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
Swapping the rules around will not fix the issue either:
|
|
711
|
+
|
|
712
|
+
```css
|
|
713
|
+
/* Also unsafe to use this CSS */
|
|
714
|
+
|
|
715
|
+
.grid {
|
|
716
|
+
display: grid;
|
|
717
|
+
grid-template-columns: repeat(3, 1fr);
|
|
718
|
+
grid-template-rows: repeat(3, 1fr);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
.grid-cell {
|
|
722
|
+
grid-column: 2;
|
|
723
|
+
grid-row: 2;
|
|
724
|
+
}
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
One way to deal with this issue is to disable autoplacement in the
|
|
728
|
+
grid-declaration rule:
|
|
729
|
+
|
|
730
|
+
```css
|
|
731
|
+
/* Disable autoplacement to fix the issue */
|
|
732
|
+
|
|
733
|
+
.grid {
|
|
734
|
+
/* autoprefixer grid: no-autoplace */
|
|
735
|
+
display: grid;
|
|
736
|
+
grid-template-columns: repeat(3, 1fr);
|
|
737
|
+
grid-template-rows: repeat(3, 1fr);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
.grid-cell {
|
|
741
|
+
grid-column: 2;
|
|
742
|
+
grid-row: 2;
|
|
743
|
+
}
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
The absolute best way to integrate autoplacement into already existing projects though is
|
|
747
|
+
to leave autoplacement turned off by default and then use a control comment to enable it
|
|
748
|
+
when needed. This method is far less likely to cause something on the site to break.
|
|
749
|
+
|
|
750
|
+
```css
|
|
751
|
+
/* Disable autoplacement by default in old projects */
|
|
752
|
+
/* autoprefixer grid: no-autoplace */
|
|
753
|
+
|
|
754
|
+
/* Old code will function the same way it always has */
|
|
755
|
+
.old-grid {
|
|
756
|
+
display: grid;
|
|
757
|
+
grid-template-columns: repeat(3, 1fr);
|
|
758
|
+
grid-template-rows: repeat(3, 1fr);
|
|
759
|
+
}
|
|
760
|
+
.old-grid-cell {
|
|
761
|
+
grid-column: 2;
|
|
762
|
+
grid-row: 2;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/* Enable autoplacement when you want to use it in new code */
|
|
766
|
+
.new-autoplace-friendly-grid {
|
|
767
|
+
/* autoprefixer grid: autoplace */
|
|
768
|
+
display: grid;
|
|
769
|
+
grid-template-columns: repeat(3, 1fr);
|
|
770
|
+
grid-template-rows: repeat(3, auto);
|
|
771
|
+
}
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
Note that the `grid: "no-autoplace"` setting and the
|
|
775
|
+
`/* autoprefixer grid: no-autoplace */` control comment share identical functionality
|
|
776
|
+
to the `grid: true` setting and the `/* autoprefixer grid: on */` control comment.
|
|
777
|
+
There is no need to refactor old code to use `no-autoplace` in place of the old
|
|
778
|
+
`true` and `on` statements.
|
|
779
|
+
|
|
780
|
+
### Autoplacement limitations
|
|
781
|
+
|
|
782
|
+
#### Both columns and rows must be defined
|
|
783
|
+
|
|
784
|
+
Autoplacement only works inside the explicit grid. The columns and rows need to be defined
|
|
785
|
+
so that Autoprefixer knows how many `nth-child` selectors to generate.
|
|
786
|
+
|
|
787
|
+
```css
|
|
788
|
+
.not-allowed {
|
|
789
|
+
display: grid;
|
|
790
|
+
grid-template-columns: repeat(3, 1fr);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
.is-allowed {
|
|
794
|
+
display: grid;
|
|
795
|
+
grid-template-columns: repeat(3, 1fr);
|
|
796
|
+
grid-template-rows: repeat(10, auto);
|
|
797
|
+
}
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
#### Repeat auto-fit and auto-fill are not supported
|
|
801
|
+
|
|
802
|
+
The `repeat(auto-fit, ...)` and `repeat(auto-fill, ...)` grid functionality relies on
|
|
803
|
+
knowledge from the browser about screen dimensions and the number of available grid
|
|
804
|
+
items for it to work properly. Autoprefixer does not have access to this information
|
|
805
|
+
so unfortunately this little snippet will _never_ be IE friendly.
|
|
806
|
+
|
|
807
|
+
```css
|
|
808
|
+
.grid {
|
|
809
|
+
/* This will never be IE friendly */
|
|
810
|
+
grid-template-columns: repeat(auto-fit, min-max(200px, 1fr))
|
|
811
|
+
}
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
#### No manual cell placement or column/row spans allowed inside an autoplacement grid
|
|
815
|
+
|
|
816
|
+
Elements must not be manually placed or given column/row spans inside an autoplacement
|
|
817
|
+
grid. Only the most basic of autoplacement grids are supported. Grid cells can still be
|
|
818
|
+
placed manually outside the the explicit grid though. Support for manually placing
|
|
819
|
+
individual grid cells inside an explicit autoplacement grid is planned for a
|
|
820
|
+
future release.
|
|
821
|
+
|
|
822
|
+
```css
|
|
823
|
+
.autoplacement-grid {
|
|
824
|
+
display: grid;
|
|
825
|
+
grid-template-columns: repeat(3, 1fr);
|
|
826
|
+
grid-template-rows: repeat(3, auto);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/*
|
|
830
|
+
grid cells placed inside the explicit grid
|
|
831
|
+
will break the layout in IE
|
|
832
|
+
*/
|
|
833
|
+
.not-permitted-grid-cell {
|
|
834
|
+
grid-column: 1;
|
|
835
|
+
grid-row: 1;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/*
|
|
839
|
+
grid cells placed outside the
|
|
840
|
+
explicit grid will work in IE
|
|
841
|
+
*/
|
|
842
|
+
.permitted-grid-cell {
|
|
843
|
+
grid-column: 1 / span 2;
|
|
844
|
+
grid-row: 4;
|
|
845
|
+
}
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
If manual cell placement is required, we recommend using `grid-template` or
|
|
849
|
+
`grid-template-areas` instead:
|
|
850
|
+
|
|
851
|
+
```css
|
|
852
|
+
.page {
|
|
853
|
+
display: grid;
|
|
854
|
+
grid-gap: 30px;
|
|
855
|
+
grid-template:
|
|
856
|
+
"head head"
|
|
857
|
+
"nav main" minmax(100px, 1fr)
|
|
858
|
+
"foot foot" /
|
|
859
|
+
200px 1fr;
|
|
860
|
+
}
|
|
861
|
+
.page__head {
|
|
862
|
+
grid-area: head;
|
|
863
|
+
}
|
|
864
|
+
.page__nav {
|
|
865
|
+
grid-area: nav;
|
|
866
|
+
}
|
|
867
|
+
.page__main {
|
|
868
|
+
grid-area: main;
|
|
869
|
+
}
|
|
870
|
+
.page__footer {
|
|
871
|
+
grid-area: foot;
|
|
872
|
+
}
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
#### Do not create `::before` and `::after` pseudo elements
|
|
876
|
+
|
|
877
|
+
Let's say you have this HTML:
|
|
878
|
+
|
|
879
|
+
```html
|
|
880
|
+
<div class="grid">
|
|
881
|
+
<div class="grid-cell"></div>
|
|
882
|
+
</div>
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
And you write this CSS:
|
|
886
|
+
|
|
887
|
+
```css
|
|
888
|
+
.grid {
|
|
889
|
+
display: grid;
|
|
890
|
+
grid-template-columns: 1fr 1fr;
|
|
891
|
+
grid-template-rows: auto;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
.grid::before {
|
|
895
|
+
content: 'before';
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
.grid::after {
|
|
899
|
+
content: 'after';
|
|
900
|
+
}
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
This will be the output:
|
|
904
|
+
|
|
905
|
+
```css
|
|
906
|
+
.grid {
|
|
907
|
+
display: -ms-grid;
|
|
908
|
+
display: grid;
|
|
909
|
+
-ms-grid-columns: 1fr 1fr;
|
|
910
|
+
grid-template-columns: 1fr 1fr;
|
|
911
|
+
-ms-grid-rows: auto;
|
|
912
|
+
grid-template-rows: auto;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
.grid > *:nth-child(1) {
|
|
916
|
+
-ms-grid-row: 1;
|
|
917
|
+
-ms-grid-column: 1;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
.grid > *:nth-child(2) {
|
|
922
|
+
-ms-grid-row: 1;
|
|
923
|
+
-ms-grid-column: 2;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
.grid::before {
|
|
927
|
+
content: 'before';
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
.grid::after {
|
|
931
|
+
content: 'after';
|
|
932
|
+
}
|
|
933
|
+
```
|
|
934
|
+
|
|
935
|
+
IE will place `.grid-cell`, `::before` and `::after` in row 1 column 1.
|
|
936
|
+
Modern browsers on the other hand will place `::before` in row 1 column 1,
|
|
937
|
+
`.grid-cell` in row 1 column 2, and `::after` in row 2 column 1.
|
|
938
|
+
|
|
939
|
+
See this [Code Pen](https://codepen.io/daniel-tonon/pen/gBymVw) to see a visualization
|
|
940
|
+
of the issue. View the Code Pen in both a modern browser and IE to see the difference.
|
|
941
|
+
|
|
942
|
+
Note that you can still create `::before` and `::after` elements as long as you manually
|
|
943
|
+
place them outside the explicit grid.
|
|
944
|
+
|
|
945
|
+
#### When changing the `grid gap` value, columns and rows must be re-declared
|
|
946
|
+
|
|
947
|
+
If you wish to change the size of a `grid-gap`, you will need to redeclare the grid columns and rows.
|
|
948
|
+
|
|
949
|
+
```css
|
|
950
|
+
.grid {
|
|
951
|
+
display: grid;
|
|
952
|
+
grid-template-columns: 1fr 1fr;
|
|
953
|
+
grid-template-rows: auto;
|
|
954
|
+
grid-gap: 50px;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/* This will *NOT* work in IE */
|
|
958
|
+
@media (max-width: 600px) {
|
|
959
|
+
.grid {
|
|
960
|
+
grid-gap: 20px;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/* This will *NOT* work in IE */
|
|
965
|
+
.grid.small-gap {
|
|
966
|
+
grid-gap: 20px;
|
|
967
|
+
}
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
```css
|
|
971
|
+
.grid {
|
|
972
|
+
display: grid;
|
|
973
|
+
grid-template-columns: 1fr 1fr;
|
|
974
|
+
grid-template-rows: auto;
|
|
975
|
+
grid-gap: 50px;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/* This *WILL* work in IE */
|
|
979
|
+
@media (max-width: 600px) {
|
|
980
|
+
.grid {
|
|
981
|
+
grid-template-columns: 1fr 1fr;
|
|
982
|
+
grid-template-rows: auto;
|
|
983
|
+
grid-gap: 20px;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/* This *WILL* work in IE */
|
|
988
|
+
.grid.small-gap {
|
|
989
|
+
grid-template-columns: 1fr 1fr;
|
|
990
|
+
grid-template-rows: auto;
|
|
991
|
+
grid-gap: 20px;
|
|
992
|
+
}
|
|
993
|
+
```
|
|
582
994
|
|
|
583
995
|
## Debug
|
|
584
996
|
|