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.

198 lines
6.1 KiB

  1. # PostCSS Logical Properties and Values [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
  2. [![NPM Version][npm-img]][npm-url]
  3. [![CSS Standard Status][css-img]][css-url]
  4. [![Build Status][cli-img]][cli-url]
  5. [![Support Chat][git-img]][git-url]
  6. [PostCSS Logical Properties and Values] lets you use logical, rather than
  7. physical, direction and dimension mappings in CSS, following the
  8. [CSS Logical Properties and Values] specification.
  9. ```pcss
  10. .banner {
  11. color: #222222;
  12. inset: logical 0 5px 10px;
  13. padding-inline: 20px 40px;
  14. resize: block;
  15. transition: color 200ms;
  16. }
  17. /* becomes */
  18. .banner:dir(ltr) {
  19. padding-left: 20px; padding-right: 40px;
  20. }
  21. .banner:dir(rtl) {
  22. padding-right: 20px; padding-left: 40px;
  23. }
  24. .banner {
  25. resize: vertical;
  26. transition: color 200ms;
  27. }
  28. /* or, when used with { dir: 'ltr' } */
  29. .banner {
  30. color: #222222;
  31. top: 0; left: 5px; bottom: 10px; right: 5px;
  32. padding-left: 20px; padding-right: 40px;
  33. resize: vertical;
  34. transition: color 200ms;
  35. }
  36. /* or, when used with { preserve: true } */
  37. .banner:dir(ltr) {
  38. padding-left: 20px; padding-right: 40px;
  39. }
  40. .banner:dir(rtl) {
  41. padding-right: 20px; padding-left: 40px;
  42. }
  43. .banner {
  44. color: #222222;
  45. top: 0; left: 5px; bottom: 10px; right: 5px;
  46. inset: logical 0 5px 10px;
  47. padding-inline: 20px 40px;
  48. resize: block;
  49. resize: vertical;
  50. transition: color 200ms;
  51. }
  52. ```
  53. These shorthand properties set values for physical properties by default.
  54. Specifying the `logical` keyboard at the beginning of the property value will
  55. transform the flow-relative values afterward into both physical LTR and RTL
  56. properties:
  57. #### Logical Borders
  58. - `border`, `border-block`, `border-block-start`, `border-block-end`,
  59. `border-inline`, `border-inline-start`, `border-inline-end`, `border-start`,
  60. `border-end`, `border-color`, `border-block-color`,
  61. `border-block-start-color`, `border-block-end-color`, `border-inline-color`,
  62. `border-inline-start-color`, `border-inline-end-color`, `border-start-color`,
  63. `border-end-color`, `border-style`, `border-block-style`,
  64. `border-block-start-style`, `border-block-end-style`, `border-inline-style`,
  65. `border-inline-start-style`, `border-inline-end-style`, `border-start-style`,
  66. `border-end-style`, `border-width`, `border-block-width`,
  67. `border-block-start-width`, `border-block-end-width`, `border-inline-width`,
  68. `border-inline-start-width`, `border-inline-end-width`, `border-start-width`,
  69. `border-end-width`
  70. #### Logical Offsets
  71. - `inset`, `inset-block`, `inset-block-start`, `inset-block-end`,
  72. `inset-inline`, `inset-inline-start`, `inset-inline-end`, `inset-start`,
  73. `inset-end`
  74. #### Logical Margins
  75. - `margin`, `margin-block`, `margin-block-start`, `margin-block-end`,
  76. `margin-inline`, `margin-inline-start`, `margin-inline-end`, `margin-start`,
  77. `margin-end`
  78. #### Logical Paddings
  79. - `padding`, `padding-block`, `padding-block-start`, `padding-block-end`,
  80. `padding-inline`, `padding-inline-start`, `padding-inline-end`,
  81. `padding-start`, `padding-end`
  82. #### Logical Sizes
  83. - `block-size`, `inline-size`
  84. #### Flow-Relative Values
  85. - `clear: inline-start`, `clear: inline-end`, `float: inline-start`,
  86. `float: inline-end`, `text-align: start`, `text-align: end`
  87. ---
  88. By default, [PostCSS Logical Properties and Values] creates fallback selectors
  89. which require at least one `[dir]` attribute in your HTML. If you don’t have
  90. any `[dir]` attributes, consider using the following JavaScript:
  91. ```js
  92. // force at least one dir attribute (this can run at any time)
  93. document.documentElement.dir=document.documentElement.dir||'ltr';
  94. ```
  95. Otherwise, consider using the `dir` option to transform all logical properties
  96. and values to a specific direction.
  97. ```js
  98. require('postcss-logical')({
  99. dir: 'ltr'
  100. });
  101. ```
  102. ## Usage
  103. Add [PostCSS Logical Properties and Values] to your project:
  104. ```bash
  105. npm install postcss-logical --save-dev
  106. ```
  107. Use [PostCSS Logical Properties and Values] to process your CSS:
  108. ```js
  109. const postcssLogical = require('postcss-logical');
  110. postcssLogical.process(YOUR_CSS /*, processOptions, pluginOptions */);
  111. ```
  112. Or use it as a [PostCSS] plugin:
  113. ```js
  114. const postcss = require('postcss');
  115. const postcssLogical = require('postcss-logical');
  116. postcss([
  117. postcssLogical(/* pluginOptions */)
  118. ]).process(YOUR_CSS /*, processOptions */);
  119. ```
  120. [PostCSS Logical Properties and Values] runs in all Node environments, with
  121. special instructions for:
  122. | [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) |
  123. | --- | --- | --- | --- | --- | --- |
  124. ## Options
  125. ### dir
  126. The `dir` option determines how directional fallbacks should be added to CSS.
  127. By default, fallbacks replace the logical declaration with nested `:dir`
  128. pseudo-classes. If `dir` is defined as `ltr` or `rtl` then only the left or
  129. right directional fallbacks will replace the logical declarations. If
  130. `preserve` is defined as `true`, then the `dir` option will be ignored.
  131. ### preserve
  132. The `preserve` option determines whether directional fallbacks should be added
  133. before logical declarations without replacing them. By default, directional
  134. fallbacks replace logical declaration. If `preserve` is defined as `true`, then
  135. the `dir` option will be ignored.
  136. [css-img]: https://cssdb.org/badge/logical-properties-and-values.svg
  137. [css-url]: https://cssdb.org/#logical-properties-and-values
  138. [cli-img]: https://img.shields.io/travis/jonathantneal/postcss-logical.svg
  139. [cli-url]: https://travis-ci.org/jonathantneal/postcss-logical
  140. [git-img]: https://img.shields.io/badge/support-chat-blue.svg
  141. [git-url]: https://gitter.im/postcss/postcss
  142. [npm-img]: https://img.shields.io/npm/v/postcss-logical.svg
  143. [npm-url]: https://www.npmjs.com/package/postcss-logical
  144. [CSS Logical Properties and Values]: https://drafts.csswg.org/css-logical/
  145. [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
  146. [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
  147. [PostCSS]: https://github.com/postcss/postcss
  148. [PostCSS Loader]: https://github.com/postcss/postcss-loader
  149. [PostCSS Logical Properties and Values]: https://github.com/jonathantneal/postcss-logical