web 3d图形渲染器
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.

207 lines
5.0 KiB

  1. # PostCSS Normalize [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
  2. [![NPM Version][npm-img]][npm-url]
  3. [![Build Status][cli-img]][cli-url]
  4. [![Support Chat][git-img]][git-url]
  5. [PostCSS Normalize] lets you use the parts of [normalize.css] or [sanitize.css]
  6. that you need from your [browserslist].
  7. ```css
  8. @import "normalize.css";
  9. ```
  10. ```css
  11. @import "sanitize.css";
  12. ```
  13. **PostCSS Normalize** uses a non-opinionated version of [normalize.css], but
  14. an opinionated version may also be used.
  15. ```css
  16. @import "normalize.css/opinionated.css";
  17. ```
  18. ### Examples
  19. Here is a sample of what **normalize.css** looks like when the **browserslist**
  20. is `ie >= 9`:
  21. ```css
  22. /**
  23. * Add the correct display in IE 9-.
  24. */
  25. audio,
  26. video {
  27. display: inline-block;
  28. }
  29. /**
  30. * Remove the border on images inside links in IE 10-.
  31. */
  32. img {
  33. border-style: none;
  34. }
  35. ```
  36. And here is the same sample when the **browserslist** is `ie >= 10`:
  37. ```css
  38. /**
  39. * Remove the border on images inside links in IE 10-.
  40. */
  41. img {
  42. border-style: none;
  43. }
  44. ```
  45. ## Usage
  46. Add [PostCSS Normalize] to your project:
  47. ```bash
  48. npm install postcss-normalize --save-dev
  49. ```
  50. Add a [browserslist] entry in `package.json`:
  51. ```json
  52. {
  53. "browserslist": "last 2 versions"
  54. }
  55. ```
  56. Use **PostCSS Normalize** to process your CSS:
  57. ```js
  58. const postcssNormalize = require('postcss-normalize')
  59. postcssNormalize.process(YOUR_CSS /*, processOptions, pluginOptions */)
  60. ```
  61. Or use it as a [PostCSS] plugin:
  62. ```js
  63. const postcss = require('postcss')
  64. const postcssNormalize = require('postcss-normalize')
  65. postcss([
  66. postcssNormalize(/* pluginOptions */)
  67. ]).process(YOUR_CSS /*, processOptions */)
  68. ```
  69. **PostCSS Normalize** runs in all Node environments, with special instructions
  70. for:
  71. | [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) |
  72. | --- | --- | --- | --- | --- | --- |
  73. ## PostCSS Import Usage
  74. **PostCSS Normalize** includes a `postcssImport` function to configure
  75. [PostCSS Import] and allow you to continue using the `@import` syntax.
  76. ```js
  77. const postcss = require('postcss')
  78. const postcssImport = require('postcss-import')
  79. const postcssNormalize = require('postcss-normalize')
  80. postcss([
  81. postcssImport(
  82. postcssNormalize(
  83. /* pluginOptions (for PostCSS Normalize) */
  84. ).postcssImport(
  85. /* pluginOptions (for PostCSS Import) */
  86. )
  87. )
  88. ]) // now you can use @import "normalize.css", etc. again
  89. ```
  90. Alternatively, use `@import-normalize` or `@import-sanitize` to avoid conflicts
  91. with `@import` transforms.
  92. ```pcss
  93. @import-normalize;
  94. ```
  95. ```pcss
  96. @import-normalize "opinionated.css";
  97. ```
  98. ```pcss
  99. @import-sanitize;
  100. ```
  101. ## Options
  102. ### allowDuplicates
  103. The `allowDuplicates` option determines whether multiple, duplicate insertions
  104. of CSS libraries are allowed. By default, duplicate libraries are omitted.
  105. ```js
  106. postcssNormalize({ allowDuplicates: true })
  107. ```
  108. ### forceImport
  109. The `forceImport` option defines CSS libraries that will be inserted at the
  110. beginning of the CSS file. Unless overriden by `allowDuplicates`, duplicate
  111. CSS libraries would still be omitted.
  112. ```js
  113. postcssNormalize({ forceImport: true })
  114. ```
  115. Specific CSS libraries may be defined.
  116. ```js
  117. postcssNormalize({
  118. forceImport: 'sanitize.css'
  119. })
  120. ```
  121. ### browsers
  122. The `browsers` option defines an override of the project’s **browserslist** for
  123. **PostCSS Normalize**. This option should be avoided in leui of a browserslist
  124. file.
  125. ```js
  126. postcssNormalize({ browsers: 'last 2 versions' })
  127. ```
  128. ## CSS Libraries
  129. **PostCSS Normalize** can include [normalize.css] or [sanitize.css] and
  130. configure either with the following combinations:
  131. ```css
  132. @import "normalize"; /* also, @import "normalize.css" */
  133. @import "normalize/opinionated"; /* also, @import "normalize.css/opinionated.css", @import "normalize.css/*" */
  134. @import "sanitize"; /* also, @import "sanitize.css" */
  135. @import "sanitize/forms"; /* also, @import "sanitize.css/forms.css" */
  136. @import "sanitize/typography"; /* also, @import "sanitize.css/typography.css" */
  137. @import "sanitize/page"; /* also, @import "sanitize.css/page.css" */
  138. @import "sanitize/*"; /* also, @import "sanitize.css/*" (sanitize + all additions) */
  139. ```
  140. [cli-img]: https://img.shields.io/travis/csstools/postcss-normalize/master.svg
  141. [cli-url]: https://travis-ci.org/csstools/postcss-normalize
  142. [git-img]: https://img.shields.io/badge/support-chat-blue.svg
  143. [git-url]: https://gitter.im/postcss/postcss
  144. [npm-img]: https://img.shields.io/npm/v/postcss-normalize.svg
  145. [npm-url]: https://www.npmjs.com/package/postcss-normalize
  146. [browserslist]: http://browserl.ist/
  147. [CSS Libraries]: #css-libraries
  148. [normalize.css]: https://github.com/csstools/normalize.css
  149. [Options]: #options
  150. [PostCSS]: https://github.com/postcss/postcss
  151. [PostCSS Import]: https://github.com/postcss/postcss-import
  152. [PostCSS Import Usage]: #postcss-import-usage
  153. [PostCSS Normalize]: https://github.com/csstools/postcss-normalize
  154. [sanitize.css]: https://github.com/csstools/sanitize.css