Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. # Autoprefixer [![Cult Of Martians][cult-img]][cult]
  2. <img align="right" width="94" height="71"
  3. src="http://postcss.github.io/autoprefixer/logo.svg"
  4. title="Autoprefixer logo by Anton Lovchikov">
  5. [PostCSS] plugin to parse CSS and add vendor prefixes to CSS rules using values
  6. from [Can I Use]. It is [recommended] by Google and used in Twitter and Alibaba.
  7. Write your CSS rules without vendor prefixes (in fact, forget about them
  8. entirely):
  9. ```css
  10. ::placeholder {
  11. color: gray;
  12. }
  13. .image {
  14. background-image: url(image@1x.png);
  15. }
  16. @media (min-resolution: 2dppx) {
  17. .image {
  18. background-image: url(image@2x.png);
  19. }
  20. }
  21. ```
  22. Autoprefixer will use the data based on current browser popularity and property
  23. support to apply prefixes for you. You can try the [interactive demo]
  24. of Autoprefixer.
  25. ```css
  26. ::-moz-placeholder {
  27. color: gray;
  28. }
  29. :-ms-input-placeholder {
  30. color: gray;
  31. }
  32. ::-ms-input-placeholder {
  33. color: gray;
  34. }
  35. ::placeholder {
  36. color: gray;
  37. }
  38. .image {
  39. background-image: url(image@1x.png);
  40. }
  41. @media (-webkit-min-device-pixel-ratio: 2),
  42. (min-resolution: 2dppx) {
  43. .image {
  44. background-image: url(image@2x.png);
  45. }
  46. }
  47. ```
  48. Twitter account for news and releases: [@autoprefixer].
  49. <a href="https://evilmartians.com/?utm_source=autoprefixer">
  50. <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
  51. </a>
  52. [interactive demo]: https://autoprefixer.github.io/
  53. [@autoprefixer]: https://twitter.com/autoprefixer
  54. [recommended]: https://developers.google.com/web/tools/setup/setup-buildtools#dont_trip_up_with_vendor_prefixes
  55. [Can I Use]: https://caniuse.com/
  56. [cult-img]: http://cultofmartians.com/assets/badges/badge.svg
  57. [PostCSS]: https://github.com/postcss/postcss
  58. [cult]: http://cultofmartians.com/tasks/autoprefixer-grid.html
  59. ## Contents
  60. * [Contents](#contents)
  61. * [Browsers](#browsers)
  62. * [FAQ](#faq)
  63. * [Does Autoprefixer polyfill Grid Layout for IE?](#does-autoprefixer-polyfill-grid-layout-for-ie)
  64. * [Does it add polyfills?](#does-it-add-polyfills)
  65. * [Why doesn’t Autoprefixer add prefixes to `border-radius`?](#why-doesnt-autoprefixer-add-prefixes-to-border-radius)
  66. * [Why does Autoprefixer use unprefixed properties in `@-webkit-keyframes`?](#why-does-autoprefixer-use-unprefixed-properties-in--webkit-keyframes)
  67. * [How to work with legacy `-webkit-` only code?](#how-to-work-with-legacy--webkit--only-code)
  68. * [Does Autoprefixer add `-epub-` prefix?](#does-autoprefixer-add--epub--prefix)
  69. * [Why doesn’t Autoprefixer transform generic font-family `system-ui`?](#why-doesnt-autoprefixer-transform-generic-font-family-system-ui)
  70. * [Usage](#usage)
  71. * [Gulp](#gulp)
  72. * [Webpack](#webpack)
  73. * [CSS-in-JS](#css-in-js)
  74. * [CLI](#cli)
  75. * [Other Build Tools](#other-build-tools)
  76. * [Preprocessors](#preprocessors)
  77. * [GUI Tools](#gui-tools)
  78. * [JavaScript](#javascript)
  79. * [Text Editors and IDE](#text-editors-and-ide)
  80. * [Warnings](#warnings)
  81. * [Disabling](#disabling)
  82. * [Prefixes](#prefixes)
  83. * [Features](#features)
  84. * [Control Comments](#control-comments)
  85. * [Options](#options)
  86. * [Environment Variables](#environment-variables)
  87. * [Using environment variables to support CSS Grid prefixes in Create React App](#using-environment-variables-to-support-css-grid-prefixes-in-create-react-app)
  88. * [Grid Autoplacement support in IE](#grid-autoplacement-support-in-ie)
  89. * [Beware of enabling autoplacement in old projects](#beware-of-enabling-autoplacement-in-old-projects)
  90. * [Autoplacement limitations](#autoplacement-limitations)
  91. * [Both columns and rows must be defined](#both-columns-and-rows-must-be-defined)
  92. * [Repeat auto-fit and auto-fill are not supported](#repeat-auto-fit-and-auto-fill-are-not-supported)
  93. * [No manual cell placement or column/row spans allowed inside an autoplacement grid](#no-manual-cell-placement-or-columnrow-spans-allowed-inside-an-autoplacement-grid)
  94. * [Do not create `::before` and `::after` pseudo elements](#do-not-create-before-and-after-pseudo-elements)
  95. * [When changing the `grid gap` value, columns and rows must be re-declared](#when-changing-the-grid-gap-value-columns-and-rows-must-be-re-declared)
  96. * [Debug](#debug)
  97. * [Security Contact](#security-contact)
  98. * [For Enterprise](#for-enterprise)
  99. ## Browsers
  100. Autoprefixer uses [Browserslist], so you can specify the browsers
  101. you want to target in your project with queries like `> 5%`
  102. (see [Best Practices]).
  103. The best way to provide browsers is a `.browserslistrc` file in your project
  104. root, or by adding a `browserslist` key to your `package.json`.
  105. We recommend the use of these options over passing options to Autoprefixer so
  106. that the config can be shared with other tools such as [babel-preset-env] and
  107. [Stylelint].
  108. See [Browserslist docs] for queries, browser names, config format, and defaults.
  109. [Browserslist docs]: https://github.com/browserslist/browserslist#queries
  110. [babel-preset-env]: https://github.com/babel/babel/tree/master/packages/babel-preset-env
  111. [Best Practices]: https://github.com/browserslist/browserslist#best-practices
  112. [Browserslist]: https://github.com/browserslist/browserslist
  113. [Stylelint]: https://stylelint.io/
  114. ## FAQ
  115. ### Does Autoprefixer polyfill Grid Layout for IE?
  116. Autoprefixer can be used to translate modern CSS Grid syntax into IE 10
  117. and IE 11 syntax, but this polyfill will not work in 100% of cases.
  118. This is why it is disabled by default.
  119. First, you need to enable Grid prefixes by using either the `grid: "autoplace"`
  120. option or the `/* autoprefixer grid: autoplace */` control comment.
  121. Also you can use environment variable to enable Grid:
  122. `AUTOPREFIXER_GRID=autoplace npm build`.
  123. Second, you need to test every fix with Grid in IE. It is not an enable and
  124. forget feature, but it is still very useful.
  125. Financial Times and Yandex use it in production.
  126. Third, there is only very limited auto placement support. Read the
  127. [Grid Autoplacement support in IE](#grid-autoplacement-support-in-ie) section
  128. for more details.
  129. Fourth, if you are not using the autoplacement feature, the best way
  130. to use Autoprefixer is by using `grid-template` or `grid-template-areas`.
  131. ```css
  132. .page {
  133. display: grid;
  134. grid-gap: 33px;
  135. grid-template:
  136. "head head head" 1fr
  137. "nav main main" minmax(100px, 1fr)
  138. "nav foot foot" 2fr /
  139. 1fr 100px 1fr;
  140. }
  141. .page__head {
  142. grid-area: head;
  143. }
  144. .page__nav {
  145. grid-area: nav;
  146. }
  147. .page__main {
  148. grid-area: main;
  149. }
  150. .page__footer {
  151. grid-area: foot;
  152. }
  153. ```
  154. See also:
  155. * [The guide about Grids in IE and Autoprefixer].
  156. * [`postcss-gap-properties`] to use new `gap` property
  157. instead of old `grid-gap`.
  158. * [`postcss-grid-kiss`] has alternate “everything in one property” syntax,
  159. which makes using Autoprefixer’s Grid translations safer.
  160. [The guide about Grids in IE and Autoprefixer]: https://css-tricks.com/css-grid-in-ie-css-grid-and-the-new-autoprefixer/
  161. [`postcss-gap-properties`]: https://github.com/jonathantneal/postcss-gap-properties
  162. [`postcss-grid-kiss`]: https://github.com/sylvainpolletvillard/postcss-grid-kiss
  163. ### Does it add polyfills?
  164. No. Autoprefixer only adds prefixes.
  165. Most new CSS features will require client side JavaScript to handle a new
  166. behavior correctly.
  167. Depending on what you consider to be a “polyfill”, you can take a look at some
  168. other tools and libraries. If you are just looking for syntax sugar,
  169. you might take a look at:
  170. - [postcss-preset-env] is a plugins preset with polyfills and Autoprefixer
  171. to write future CSS today.
  172. - [Oldie], a PostCSS plugin that handles some IE hacks (opacity, rgba, etc).
  173. - [postcss-flexbugs-fixes], a PostCSS plugin to fix flexbox issues.
  174. [postcss-flexbugs-fixes]: https://github.com/luisrudge/postcss-flexbugs-fixes
  175. [postcss-preset-env]: https://github.com/jonathantneal/postcss-preset-env
  176. [Oldie]: https://github.com/jonathantneal/oldie
  177. ### Why doesn’t Autoprefixer add prefixes to `border-radius`?
  178. Developers are often surprised by how few prefixes are required today.
  179. If Autoprefixer doesn’t add prefixes to your CSS, check if they’re still
  180. required on [Can I Use].
  181. [Can I Use]: https://caniuse.com/
  182. ### Why does Autoprefixer use unprefixed properties in `@-webkit-keyframes`?
  183. Browser teams can remove some prefixes before others, so we try to use all
  184. combinations of prefixed/unprefixed values.
  185. ### How to work with legacy `-webkit-` only code?
  186. Autoprefixer needs unprefixed property to add prefixes. So if you only
  187. wrote `-webkit-gradient` without W3C’s `gradient`,
  188. Autoprefixer will not add other prefixes.
  189. But [PostCSS] has plugins to convert CSS to unprefixed state.
  190. Use [postcss-unprefix] before Autoprefixer.
  191. [postcss-unprefix]: https://github.com/gucong3000/postcss-unprefix
  192. ### Does Autoprefixer add `-epub-` prefix?
  193. No, Autoprefixer works only with browsers prefixes from Can I Use.
  194. But you can use [postcss-epub] for prefixing ePub3 properties.
  195. [postcss-epub]: https://github.com/Rycochet/postcss-epub
  196. ### Why doesn’t Autoprefixer transform generic font-family `system-ui`?
  197. `system-ui` is technically not a prefix and the transformation is not
  198. future-proof. You can use [postcss-font-family-system-ui] to transform
  199. `system-ui` to a practical font-family list.
  200. [postcss-font-family-system-ui]: https://github.com/JLHwung/postcss-font-family-system-ui
  201. ## Usage
  202. ### Gulp
  203. In Gulp you can use [gulp-postcss] with `autoprefixer` npm package.
  204. ```js
  205. gulp.task('autoprefixer', () => {
  206. const autoprefixer = require('autoprefixer')
  207. const sourcemaps = require('gulp-sourcemaps')
  208. const postcss = require('gulp-postcss')
  209. return gulp.src('./src/*.css')
  210. .pipe(sourcemaps.init())
  211. .pipe(postcss([ autoprefixer() ]))
  212. .pipe(sourcemaps.write('.'))
  213. .pipe(gulp.dest('./dest'))
  214. })
  215. ```
  216. With `gulp-postcss` you also can combine Autoprefixer
  217. with [other PostCSS plugins].
  218. [gulp-postcss]: https://github.com/postcss/gulp-postcss
  219. [other PostCSS plugins]: https://github.com/postcss/postcss#plugins
  220. ### Webpack
  221. In [webpack] you can use [postcss-loader] with `autoprefixer`
  222. and [other PostCSS plugins].
  223. ```js
  224. module.exports = {
  225. module: {
  226. rules: [
  227. {
  228. test: /\.css$/,
  229. use: ["style-loader", "css-loader", "postcss-loader"]
  230. }
  231. ]
  232. }
  233. }
  234. ```
  235. And create a `postcss.config.js` with:
  236. ```js
  237. module.exports = {
  238. plugins: [
  239. require('autoprefixer')
  240. ]
  241. }
  242. ```
  243. [other PostCSS plugins]: https://github.com/postcss/postcss#plugins
  244. [postcss-loader]: https://github.com/postcss/postcss-loader
  245. [webpack]: https://webpack.js.org/
  246. ### CSS-in-JS
  247. The best way to use PostCSS with CSS-in-JS is [`astroturf`].
  248. Add its loader to your `webpack.config.js`:
  249. ```js
  250. module.exports = {
  251. module: {
  252. rules: [
  253. {
  254. test: /\.css$/,
  255. use: ['style-loader', 'postcss-loader'],
  256. },
  257. {
  258. test: /\.jsx?$/,
  259. use: ['babel-loader', 'astroturf/loader'],
  260. }
  261. ]
  262. }
  263. }
  264. ```
  265. Then create `postcss.config.js`:
  266. ```js
  267. module.exports = {
  268. plugins: [
  269. require('autoprefixer')
  270. ]
  271. }
  272. ```
  273. [`astroturf`]: https://github.com/4Catalyzer/astroturf
  274. ### CLI
  275. You can use the [postcss-cli] to run Autoprefixer from CLI:
  276. ```sh
  277. npm install postcss-cli autoprefixer
  278. npx postcss *.css --use autoprefixer -d build/
  279. ```
  280. See `postcss -h` for help.
  281. [postcss-cli]: https://github.com/postcss/postcss-cli
  282. ### Other Build Tools
  283. * **Grunt:** [grunt-postcss]
  284. * **Ruby on Rails**: [autoprefixer-rails]
  285. * **Neutrino**: [neutrino-middleware-postcss]
  286. * **Jekyll**: add `autoprefixer-rails` and `jekyll-assets` to `Gemfile`
  287. * **Brunch**: [postcss-brunch]
  288. * **Broccoli**: [broccoli-postcss]
  289. * **Middleman**: [middleman-autoprefixer]
  290. * **Mincer**: add `autoprefixer` npm package and enable it:
  291. `environment.enable('autoprefixer')`
  292. [neutrino-middleware-postcss]: https://www.npmjs.com/package/neutrino-middleware-postcss
  293. [middleman-autoprefixer]: https://github.com/middleman/middleman-autoprefixer
  294. [autoprefixer-rails]: https://github.com/ai/autoprefixer-rails
  295. [broccoli-postcss]: https://github.com/jeffjewiss/broccoli-postcss
  296. [postcss-brunch]: https://github.com/iamvdo/postcss-brunch
  297. [grunt-postcss]: https://github.com/C-Lodder/grunt-postcss
  298. #### Preprocessors
  299. * **Less**: [less-plugin-autoprefix]
  300. * **Stylus**: [autoprefixer-stylus]
  301. * **Compass**: [autoprefixer-rails#compass]
  302. [less-plugin-autoprefix]: https://github.com/less/less-plugin-autoprefix
  303. [autoprefixer-stylus]: https://github.com/jenius/autoprefixer-stylus
  304. [autoprefixer-rails#compass]: https://github.com/ai/autoprefixer-rails#compass
  305. #### GUI Tools
  306. * [CodeKit](https://codekitapp.com/help/autoprefixer/)
  307. * [Prepros](https://prepros.io)
  308. ### JavaScript
  309. You can use Autoprefixer with [PostCSS] in your Node.js application
  310. or if you want to develop an Autoprefixer plugin for a new environment.
  311. ```js
  312. const autoprefixer = require('autoprefixer')
  313. const postcss = require('postcss')
  314. postcss([ autoprefixer ]).process(css).then(result => {
  315. result.warnings().forEach(warn => {
  316. console.warn(warn.toString())
  317. })
  318. console.log(result.css)
  319. })
  320. ```
  321. There is also a [standalone build] for the browser or for a non-Node.js runtime.
  322. You can use [html-autoprefixer] to process HTML with inlined CSS.
  323. [html-autoprefixer]: https://github.com/RebelMail/html-autoprefixer
  324. [standalone build]: https://raw.github.com/ai/autoprefixer-rails/master/vendor/autoprefixer.js
  325. [PostCSS]: https://github.com/postcss/postcss
  326. ### Text Editors and IDE
  327. Autoprefixer should be used in assets build tools. Text editor plugins are not
  328. a good solution, because prefixes decrease code readability and you will need
  329. to change values in all prefixed properties.
  330. I recommend you to learn how to use build tools like [Parcel].
  331. They work much better and will open you a whole new world of useful plugins
  332. and automation.
  333. If you can’t move to a build tool, you can use text editor plugins:
  334. * [Visual Studio Code](https://github.com/mrmlnc/vscode-autoprefixer)
  335. * [Atom Editor](https://github.com/sindresorhus/atom-autoprefixer)
  336. * [Sublime Text](https://github.com/sindresorhus/sublime-autoprefixer)
  337. * [Brackets](https://github.com/mikaeljorhult/brackets-autoprefixer)
  338. [Parcel]: https://parceljs.org/
  339. ## Warnings
  340. Autoprefixer uses the [PostCSS warning API] to warn about really important
  341. problems in your CSS:
  342. * Old direction syntax in gradients.
  343. * Old unprefixed `display: box` instead of `display: flex`
  344. by latest specification version.
  345. You can get warnings from `result.warnings()`:
  346. ```js
  347. result.warnings().forEach(warn => {
  348. console.warn(warn.toString())
  349. })
  350. ```
  351. Every Autoprefixer runner should display these warnings.
  352. [PostCSS warning API]: http://api.postcss.org/Warning.html
  353. ## Disabling
  354. ### Prefixes
  355. Autoprefixer was designed to have no interface – it just works.
  356. If you need some browser specific hack just write a prefixed property
  357. after the unprefixed one.
  358. ```css
  359. a {
  360. transform: scale(0.5);
  361. -moz-transform: scale(0.6);
  362. }
  363. ```
  364. If some prefixes were generated incorrectly, please create an [issue on GitHub].
  365. [issue on GitHub]: https://github.com/postcss/autoprefixer/issues
  366. ### Features
  367. You can use these plugin options to control some of Autoprefixer’s features.
  368. * `grid: "autoplace"` will enable `-ms-` prefixes for Grid Layout including some
  369. [limited autoplacement support](#grid-autoplacement-support-in-ie).
  370. * `supports: false` will disable `@supports` parameters prefixing.
  371. * `flexbox: false` will disable flexbox properties prefixing.
  372. Or `flexbox: "no-2009"` will add prefixes only for final and IE
  373. versions of specification.
  374. * `remove: false` will disable cleaning outdated prefixes.
  375. You should set them inside the plugin like so:
  376. ```js
  377. autoprefixer({ grid: 'autoplace' })
  378. ```
  379. ### Control Comments
  380. If you do not need Autoprefixer in some part of your CSS,
  381. you can use control comments to disable Autoprefixer.
  382. ```css
  383. .a {
  384. transition: 1s; /* will be prefixed */
  385. }
  386. .b {
  387. /* autoprefixer: off */
  388. transition: 1s; /* will not be prefixed */
  389. }
  390. .c {
  391. /* autoprefixer: ignore next */
  392. transition: 1s; /* will not be prefixed */
  393. mask: url(image.png); /* will be prefixed */
  394. }
  395. ```
  396. There are three types of control comments:
  397. * `/* autoprefixer: (on|off) */`: enable/disable all Autoprefixer translations for the
  398. whole block both *before* and *after* the comment.
  399. * `/* autoprefixer: ignore next */`: disable Autoprefixer only for the next property
  400. or next rule selector or at-rule parameters (but not rule/at‑rule body).
  401. * `/* autoprefixer grid: (autoplace|no-autoplace|off) */`: control how Autoprefixer handles
  402. grid translations for the whole block:
  403. * `autoplace`: enable grid translations with autoplacement support.
  404. * `no-autoplace`: enable grid translations with autoplacement
  405. support *disabled* (alias for deprecated value `on`).
  406. * `off`: disable all grid translations.
  407. You can also use comments recursively:
  408. ```css
  409. /* autoprefixer: off */
  410. @supports (transition: all) {
  411. /* autoprefixer: on */
  412. a {
  413. /* autoprefixer: off */
  414. }
  415. }
  416. ```
  417. Note that comments that disable the whole block should not be featured in the same
  418. block twice:
  419. ```css
  420. /* How not to use block level control comments */
  421. .do-not-do-this {
  422. /* autoprefixer: off */
  423. transition: 1s;
  424. /* autoprefixer: on */
  425. transform: rotate(20deg);
  426. }
  427. ```
  428. ## Options
  429. Function `autoprefixer(options)` returns a new PostCSS plugin.
  430. See [PostCSS API] for plugin usage documentation.
  431. ```js
  432. autoprefixer({ cascade: false })
  433. ```
  434. Available options are:
  435. * `env` (string): environment for Browserslist.
  436. * `cascade` (boolean): should Autoprefixer use Visual Cascade,
  437. if CSS is uncompressed. Default: `true`
  438. * `add` (boolean): should Autoprefixer add prefixes. Default is `true`.
  439. * `remove` (boolean): should Autoprefixer [remove outdated] prefixes.
  440. Default is `true`.
  441. * `supports` (boolean): should Autoprefixer add prefixes for `@supports`
  442. parameters. Default is `true`.
  443. * `flexbox` (boolean|string): should Autoprefixer add prefixes for flexbox
  444. properties. With `"no-2009"` value Autoprefixer will add prefixes only
  445. for final and IE 10 versions of specification. Default is `true`.
  446. * `grid` (false|`"autoplace"`|`"no-autoplace"`): should Autoprefixer
  447. add IE 10-11 prefixes for Grid Layout properties?
  448. * `false` (default): prevent Autoprefixer from outputting
  449. CSS Grid translations.
  450. * `"autoplace"`: enable Autoprefixer grid translations
  451. and *include* autoplacement support. You can also use
  452. `/* autoprefixer grid: autoplace */` in your CSS.
  453. * `"no-autoplace"`: enable Autoprefixer grid translations
  454. but *exclude* autoplacement support. You can also use
  455. `/* autoprefixer grid: no-autoplace */` in your CSS.
  456. (alias for the deprecated `true` value)
  457. * `stats` (object): custom [usage statistics] for `> 10% in my stats`
  458. browsers query.
  459. * `overrideBrowserslist` (array): list of queries for target browsers.
  460. Try to not use it. The best practice is to use `.browserslistrc` config
  461. or `browserslist` key in `package.json` to share target browsers
  462. with Babel, ESLint and Stylelint. See [Browserslist docs]
  463. for available queries and default value.
  464. * `ignoreUnknownVersions` (boolean): do not raise error on unknown browser
  465. version in Browserslist config. Default is `false`.
  466. Plugin object has `info()` method for debugging purpose.
  467. You can use PostCSS processor to process several CSS files
  468. to increase performance.
  469. [usage statistics]: https://github.com/browserslist/browserslist#custom-usage-data
  470. [PostCSS API]: http://api.postcss.org
  471. ## Environment Variables
  472. * `AUTOPREFIXER_GRID`: (`autoplace`|`no-autoplace`) should Autoprefixer
  473. add IE 10-11 prefixes for Grid Layout properties?
  474. * `autoplace`: enable Autoprefixer grid translations
  475. and *include* autoplacement support.
  476. * `no-autoplace`: enable Autoprefixer grid translations
  477. but *exclude* autoplacement support.
  478. Environment variables are useful, when you want to change Autoprefixer options but don't have access to config files.
  479. [Create React App] is a good example of this.
  480. [Create React App]: (https://reactjs.org/docs/create-a-new-react-app.html#create-react-app)
  481. ### Using environment variables to support CSS Grid prefixes in Create React App
  482. 1. Install the latest version of Autoprefixer and [cross-env](https://www.npmjs.com/package/cross-env):
  483. ```
  484. npm install autoprefixer@latest cross-env --save-dev
  485. ```
  486. 2. Under `"browserslist"` > `"development"` in the package.json file, add `"last 1 ie version"`
  487. ```
  488. "browserslist": {
  489. "production": [
  490. ">0.2%",
  491. "not dead",
  492. "not op_mini all"
  493. ],
  494. "development": [
  495. "last 1 chrome version",
  496. "last 1 firefox version",
  497. "last 1 safari version",
  498. "last 1 ie version"
  499. ]
  500. }
  501. ```
  502. 3. Update `"scripts"` in the package.json file to the following:
  503. ```
  504. "scripts": {
  505. "start": "cross-env AUTOPREFIXER_GRID=autoplace react-scripts start",
  506. "build": "cross-env AUTOPREFIXER_GRID=autoplace react-scripts build",
  507. "test": "cross-env AUTOPREFIXER_GRID=autoplace react-scripts test",
  508. "eject": "react-scripts eject"
  509. },
  510. ```
  511. Replace `autoplace` with `no-autoplace` in the above example if you prefer to disable Autoprefixer Grid autoplacement support.
  512. Now when you run `npm start` you will see CSS Grid prefixes automatically being applied to your output CSS.
  513. See also [Browserslist environment variables] for more examples on how to use environment variables in your project.
  514. [Browserslist environment variables]: https://github.com/browserslist/browserslist#environment-variables
  515. ## Grid Autoplacement support in IE
  516. If the `grid` option is set to `"autoplace"`, limited autoplacement support is added to Autoprefixers grid translations. You can also use
  517. the `/* autoprefixer grid: autoplace */` control comment or
  518. `AUTOPREFIXER_GRID=autoplace npm build` environment variable.
  519. Autoprefixer will only autoplace grid cells if both `grid-template-rows`
  520. and `grid-template-columns` has been set. If `grid-template`
  521. or `grid-template-areas` has been set, Autoprefixer will use area based
  522. cell placement instead.
  523. Autoprefixer supports autoplacement by using `nth-child` CSS selectors.
  524. It creates [number of columns] x [number of rows] `nth-child` selectors.
  525. For this reason Autoplacement is only supported within the explicit grid.
  526. ```css
  527. /* Input CSS */
  528. /* autoprefixer grid: autoplace */
  529. .autoplacement-example {
  530. display: grid;
  531. grid-template-columns: 1fr 1fr;
  532. grid-template-rows: auto auto;
  533. grid-gap: 20px;
  534. }
  535. ```
  536. ```css
  537. /* Output CSS */
  538. /* autoprefixer grid: autoplace */
  539. .autoplacement-example {
  540. display: -ms-grid;
  541. display: grid;
  542. -ms-grid-columns: 1fr 20px 1fr;
  543. grid-template-columns: 1fr 1fr;
  544. -ms-grid-rows: auto 20px auto;
  545. grid-template-rows: auto auto;
  546. grid-gap: 20px;
  547. }
  548. .autoplacement-example > *:nth-child(1) {
  549. -ms-grid-row: 1;
  550. -ms-grid-column: 1;
  551. }
  552. .autoplacement-example > *:nth-child(2) {
  553. -ms-grid-row: 1;
  554. -ms-grid-column: 3;
  555. }
  556. .autoplacement-example > *:nth-child(3) {
  557. -ms-grid-row: 3;
  558. -ms-grid-column: 1;
  559. }
  560. .autoplacement-example > *:nth-child(4) {
  561. -ms-grid-row: 3;
  562. -ms-grid-column: 3;
  563. }
  564. ```
  565. ### Beware of enabling autoplacement in old projects
  566. Be careful about enabling autoplacement in any already established projects that have
  567. previously not used Autoprefixer's grid autoplacement feature before.
  568. If this was your html:
  569. ```html
  570. <div class="grid">
  571. <div class="grid-cell"></div>
  572. </div>
  573. ```
  574. The following CSS will not work as expected with the autoplacement feature enabled:
  575. ```css
  576. /* Unsafe CSS when Autoplacement is enabled */
  577. .grid-cell {
  578. grid-column: 2;
  579. grid-row: 2;
  580. }
  581. .grid {
  582. display: grid;
  583. grid-template-columns: repeat(3, 1fr);
  584. grid-template-rows: repeat(3, 1fr);
  585. }
  586. ```
  587. Swapping the rules around will not fix the issue either:
  588. ```css
  589. /* Also unsafe to use this CSS */
  590. .grid {
  591. display: grid;
  592. grid-template-columns: repeat(3, 1fr);
  593. grid-template-rows: repeat(3, 1fr);
  594. }
  595. .grid-cell {
  596. grid-column: 2;
  597. grid-row: 2;
  598. }
  599. ```
  600. One way to deal with this issue is to disable autoplacement in the
  601. grid-declaration rule:
  602. ```css
  603. /* Disable autoplacement to fix the issue */
  604. .grid {
  605. /* autoprefixer grid: no-autoplace */
  606. display: grid;
  607. grid-template-columns: repeat(3, 1fr);
  608. grid-template-rows: repeat(3, 1fr);
  609. }
  610. .grid-cell {
  611. grid-column: 2;
  612. grid-row: 2;
  613. }
  614. ```
  615. The absolute best way to integrate autoplacement into already existing projects
  616. though is to leave autoplacement turned off by default and then use a control
  617. comment to enable it when needed. This method is far less likely to cause
  618. something on the site to break.
  619. ```css
  620. /* Disable autoplacement by default in old projects */
  621. /* autoprefixer grid: no-autoplace */
  622. /* Old code will function the same way it always has */
  623. .old-grid {
  624. display: grid;
  625. grid-template-columns: repeat(3, 1fr);
  626. grid-template-rows: repeat(3, 1fr);
  627. }
  628. .old-grid-cell {
  629. grid-column: 2;
  630. grid-row: 2;
  631. }
  632. /* Enable autoplacement when you want to use it in new code */
  633. .new-autoplace-friendly-grid {
  634. /* autoprefixer grid: autoplace */
  635. display: grid;
  636. grid-template-columns: repeat(3, 1fr);
  637. grid-template-rows: repeat(3, auto);
  638. }
  639. ```
  640. Note that the `grid: "no-autoplace"` setting and the
  641. `/* autoprefixer grid: no-autoplace */` control comment share identical
  642. functionality to the `grid: true` setting and the `/* autoprefixer grid: on */`
  643. control comment. There is no need to refactor old code to use `no-autoplace`
  644. in place of the old `true` and `on` statements.
  645. ### Autoplacement limitations
  646. #### Both columns and rows must be defined
  647. Autoplacement only works inside the explicit grid. The columns and rows need to be defined
  648. so that Autoprefixer knows how many `nth-child` selectors to generate.
  649. ```css
  650. .not-allowed {
  651. display: grid;
  652. grid-template-columns: repeat(3, 1fr);
  653. }
  654. .is-allowed {
  655. display: grid;
  656. grid-template-columns: repeat(3, 1fr);
  657. grid-template-rows: repeat(10, auto);
  658. }
  659. ```
  660. #### Repeat auto-fit and auto-fill are not supported
  661. The `repeat(auto-fit, ...)` and `repeat(auto-fill, ...)` grid functionality relies on
  662. knowledge from the browser about screen dimensions and the number of available grid
  663. items for it to work properly. Autoprefixer does not have access to this information
  664. so unfortunately this little snippet will _never_ be IE friendly.
  665. ```css
  666. .grid {
  667. /* This will never be IE friendly */
  668. grid-template-columns: repeat(auto-fit, min-max(200px, 1fr))
  669. }
  670. ```
  671. #### No manual cell placement or column/row spans allowed inside an autoplacement grid
  672. Elements must not be manually placed or given column/row spans inside
  673. an autoplacement grid. Only the most basic of autoplacement grids are supported.
  674. Grid cells can still be placed manually outside the the explicit grid though.
  675. Support for manually placing individual grid cells inside an explicit
  676. autoplacement grid is planned for a future release.
  677. ```css
  678. .autoplacement-grid {
  679. display: grid;
  680. grid-template-columns: repeat(3, 1fr);
  681. grid-template-rows: repeat(3, auto);
  682. }
  683. /* Grid cells placed inside the explicit grid
  684. will break the layout in IE */
  685. .not-permitted-grid-cell {
  686. grid-column: 1;
  687. grid-row: 1;
  688. }
  689. /* Grid cells placed outside the
  690. explicit grid will work in IE */
  691. .permitted-grid-cell {
  692. grid-column: 1 / span 2;
  693. grid-row: 4;
  694. }
  695. ```
  696. If manual cell placement is required, we recommend using `grid-template` or
  697. `grid-template-areas` instead:
  698. ```css
  699. .page {
  700. display: grid;
  701. grid-gap: 30px;
  702. grid-template:
  703. "head head"
  704. "nav main" minmax(100px, 1fr)
  705. "foot foot" /
  706. 200px 1fr;
  707. }
  708. .page__head {
  709. grid-area: head;
  710. }
  711. .page__nav {
  712. grid-area: nav;
  713. }
  714. .page__main {
  715. grid-area: main;
  716. }
  717. .page__footer {
  718. grid-area: foot;
  719. }
  720. ```
  721. #### Do not create `::before` and `::after` pseudo elements
  722. Let's say you have this HTML:
  723. ```html
  724. <div class="grid">
  725. <div class="grid-cell"></div>
  726. </div>
  727. ```
  728. And you write this CSS:
  729. ```css
  730. .grid {
  731. display: grid;
  732. grid-template-columns: 1fr 1fr;
  733. grid-template-rows: auto;
  734. }
  735. .grid::before {
  736. content: 'before';
  737. }
  738. .grid::after {
  739. content: 'after';
  740. }
  741. ```
  742. This will be the output:
  743. ```css
  744. .grid {
  745. display: -ms-grid;
  746. display: grid;
  747. -ms-grid-columns: 1fr 1fr;
  748. grid-template-columns: 1fr 1fr;
  749. -ms-grid-rows: auto;
  750. grid-template-rows: auto;
  751. }
  752. .grid > *:nth-child(1) {
  753. -ms-grid-row: 1;
  754. -ms-grid-column: 1;
  755. }
  756. .grid > *:nth-child(2) {
  757. -ms-grid-row: 1;
  758. -ms-grid-column: 2;
  759. }
  760. .grid::before {
  761. content: 'before';
  762. }
  763. .grid::after {
  764. content: 'after';
  765. }
  766. ```
  767. IE will place `.grid-cell`, `::before` and `::after` in row 1 column 1.
  768. Modern browsers on the other hand will place `::before` in row 1 column 1,
  769. `.grid-cell` in row 1 column 2, and `::after` in row 2 column 1.
  770. See this [Code Pen](https://codepen.io/daniel-tonon/pen/gBymVw) to see a visualization
  771. of the issue. View the Code Pen in both a modern browser and IE to see the difference.
  772. Note that you can still create `::before` and `::after` elements as long as you manually
  773. place them outside the explicit grid.
  774. #### When changing the `grid gap` value, columns and rows must be re-declared
  775. If you wish to change the size of a `grid-gap`, you will need to redeclare the grid columns and rows.
  776. ```css
  777. .grid {
  778. display: grid;
  779. grid-template-columns: 1fr 1fr;
  780. grid-template-rows: auto;
  781. grid-gap: 50px;
  782. }
  783. /* This will *NOT* work in IE */
  784. @media (max-width: 600px) {
  785. .grid {
  786. grid-gap: 20px;
  787. }
  788. }
  789. /* This will *NOT* work in IE */
  790. .grid.small-gap {
  791. grid-gap: 20px;
  792. }
  793. ```
  794. ```css
  795. .grid {
  796. display: grid;
  797. grid-template-columns: 1fr 1fr;
  798. grid-template-rows: auto;
  799. grid-gap: 50px;
  800. }
  801. /* This *WILL* work in IE */
  802. @media (max-width: 600px) {
  803. .grid {
  804. grid-template-columns: 1fr 1fr;
  805. grid-template-rows: auto;
  806. grid-gap: 20px;
  807. }
  808. }
  809. /* This *WILL* work in IE */
  810. .grid.small-gap {
  811. grid-template-columns: 1fr 1fr;
  812. grid-template-rows: auto;
  813. grid-gap: 20px;
  814. }
  815. ```
  816. ## Debug
  817. Run `npx autoprefixer --info` in your project directory to check
  818. which browsers are selected and which properties will be prefixed:
  819. ```
  820. $ npx autoprefixer --info
  821. Browsers:
  822. Edge: 16
  823. These browsers account for 0.26% of all users globally
  824. At-Rules:
  825. @viewport: ms
  826. Selectors:
  827. ::placeholder: ms
  828. Properties:
  829. appearance: webkit
  830. flow-from: ms
  831. flow-into: ms
  832. hyphens: ms
  833. overscroll-behavior: ms
  834. region-fragment: ms
  835. scroll-snap-coordinate: ms
  836. scroll-snap-destination: ms
  837. scroll-snap-points-x: ms
  838. scroll-snap-points-y: ms
  839. scroll-snap-type: ms
  840. text-size-adjust: ms
  841. text-spacing: ms
  842. user-select: ms
  843. ```
  844. JS API is also available:
  845. ```js
  846. console.log(autoprefixer().info())
  847. ```
  848. ## Security Contact
  849. To report a security vulnerability, please use the [Tidelift security contact].
  850. Tidelift will coordinate the fix and disclosure.
  851. [Tidelift security contact]: https://tidelift.com/security
  852. ## For Enterprise
  853. Available as part of the Tidelift Subscription.
  854. The maintainers of `autoprefixer` and thousands of other packages are working
  855. with Tidelift to deliver commercial support and maintenance for the open source
  856. dependencies you use to build your applications. Save time, reduce risk,
  857. and improve code health, while paying the maintainers of the exact dependencies
  858. you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-autoprefixer?utm_source=npm-autoprefixer&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)