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.

131 lines
3.6 KiB

  1. # PostCSS Focus Within [<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. [![Gitter Chat][git-img]][git-url]
  6. [PostCSS Focus Within] lets you use the `:focus-within` pseudo-class in CSS,
  7. following the [Selectors Level 4 specification].
  8. It is the companion to the [focus-within polyfill].
  9. ```css
  10. .my-form-field:focus-within label {
  11. background-color: yellow;
  12. }
  13. /* becomes */
  14. .my-form-field[focus-within] label {
  15. background-color: yellow;
  16. }
  17. .my-form-field:focus-within label {
  18. background-color: yellow;
  19. }
  20. ```
  21. [PostCSS Focus Within] duplicates rules using the `:focus-within` pseudo-class
  22. with a `[focus-within]` attribute selector, the same selector used by the
  23. [focus-within polyfill]. This replacement selector can be changed using the
  24. `replaceWith` option. Also, the preservation of the original `:focus-within`
  25. rule can be disabled using the `preserve` option.
  26. ## Usage
  27. Add [PostCSS Focus Within] to your project:
  28. ```bash
  29. npm install postcss-focus-within --save-dev
  30. ```
  31. Use [PostCSS Focus Within] to process your CSS:
  32. ```js
  33. const postcssFocusWithin = require('postcss-focus-within');
  34. postcssFocusWithin.process(YOUR_CSS /*, processOptions, pluginOptions */);
  35. ```
  36. Or use it as a [PostCSS] plugin:
  37. ```js
  38. const postcss = require('postcss');
  39. const postcssFocusWithin = require('postcss-focus-within');
  40. postcss([
  41. postcssFocusWithin(/* pluginOptions */)
  42. ]).process(YOUR_CSS /*, processOptions */);
  43. ```
  44. [PostCSS Focus Within] runs in all Node environments, with special
  45. instructions for:
  46. | [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) |
  47. | --- | --- | --- | --- | --- | --- |
  48. ## Options
  49. ### preserve
  50. The `preserve` option defines whether the original selector should remain. By
  51. default, the original selector is preserved.
  52. ```js
  53. focusWithin({ preserve: false });
  54. ```
  55. ```css
  56. .my-form-field:focus-within label {
  57. background-color: yellow;
  58. }
  59. /* becomes */
  60. .my-form-field[focus-within] label {
  61. background-color: yellow;
  62. }
  63. ```
  64. ### replaceWith
  65. The `replaceWith` option defines the selector to replace `:focus-within`. By
  66. default, the replacement selector is `[focus-within]`.
  67. ```js
  68. focusWithin({ replaceWith: '.focus-within' });
  69. ```
  70. ```css
  71. .my-form-field:focus-within label {
  72. background-color: yellow;
  73. }
  74. /* becomes */
  75. .my-form-field.focus-within label {
  76. background-color: yellow;
  77. }
  78. .my-form-field:focus-within label {
  79. background-color: yellow;
  80. }
  81. ```
  82. [css-img]: https://cssdb.org/badge/focus-within-pseudo-class.svg
  83. [css-url]: https://cssdb.org/#focus-within-pseudo-class
  84. [cli-img]: https://img.shields.io/travis/jonathantneal/postcss-focus-within.svg
  85. [cli-url]: https://travis-ci.org/jonathantneal/postcss-focus-within
  86. [git-img]: https://img.shields.io/badge/support-chat-blue.svg
  87. [git-url]: https://gitter.im/postcss/postcss
  88. [npm-img]: https://img.shields.io/npm/v/postcss-focus-within.svg
  89. [npm-url]: https://www.npmjs.com/package/postcss-focus-within
  90. [focus-within polyfill]: https://github.com/jonathantneal/focus-within
  91. [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
  92. [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
  93. [PostCSS]: https://github.com/postcss/postcss
  94. [PostCSS Focus Within]: https://github.com/jonathantneal/postcss-focus-within
  95. [PostCSS Loader]: https://github.com/postcss/postcss-loader
  96. [Selectors Level 4 specification]: https://www.w3.org/TR/selectors-4/#the-focus-within-pseudo