| 1 | # PostCSS Pseudo Class Any Link [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
|
|---|
| 2 |
|
|---|
| 3 | [![NPM Version][npm-img]][npm-url]
|
|---|
| 4 | [![CSS Standard Status][css-img]][css-url]
|
|---|
| 5 | [![Build Status][cli-img]][cli-url]
|
|---|
| 6 | [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|---|
| 7 |
|
|---|
| 8 | [PostCSS Pseudo Class Any Link] lets you `:any-link` pseudo-class in CSS,
|
|---|
| 9 | following the [Selectors] specification.
|
|---|
| 10 |
|
|---|
| 11 | ```pcss
|
|---|
| 12 | nav :any-link > span {
|
|---|
| 13 | background-color: yellow;
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | /* becomes */
|
|---|
| 17 |
|
|---|
| 18 | nav :link > span, nav :visited > span {
|
|---|
| 19 | background-color: yellow;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | nav :any-link > span {
|
|---|
| 23 | background-color: yellow;
|
|---|
| 24 | }
|
|---|
| 25 | ```
|
|---|
| 26 |
|
|---|
| 27 | From the [proposal][Selectors]:
|
|---|
| 28 |
|
|---|
| 29 | > The `:any-link` pseudo-class represents an element that acts as the source
|
|---|
| 30 | anchor of a hyperlink. It matches an element if the element would match
|
|---|
| 31 | `:link` or `:visited`.
|
|---|
| 32 |
|
|---|
| 33 | [](https://caniuse.com/#feat=css-any-link)
|
|---|
| 34 |
|
|---|
| 35 | ## Usage
|
|---|
| 36 |
|
|---|
| 37 | Add [PostCSS Pseudo Class Any Link] to your project:
|
|---|
| 38 |
|
|---|
| 39 | ```bash
|
|---|
| 40 | npm install postcss postcss-pseudo-class-any-link --save-dev
|
|---|
| 41 | ```
|
|---|
| 42 |
|
|---|
| 43 | Use [PostCSS Pseudo Class Any Link] as a [PostCSS] plugin:
|
|---|
| 44 |
|
|---|
| 45 | ```js
|
|---|
| 46 | const postcss = require('postcss');
|
|---|
| 47 | const postcssPseudoClassAnyLink = require('postcss-pseudo-class-any-link');
|
|---|
| 48 |
|
|---|
| 49 | postcss([
|
|---|
| 50 | postcssPseudoClassAnyLink(/* pluginOptions */)
|
|---|
| 51 | ]).process(YOUR_CSS /*, processOptions */);
|
|---|
| 52 | ```
|
|---|
| 53 |
|
|---|
| 54 | [PostCSS Pseudo Class Any Link] runs in all Node environments, with special
|
|---|
| 55 | instructions for:
|
|---|
| 56 |
|
|---|
| 57 | | [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) |
|
|---|
| 58 | | --- | --- | --- | --- | --- | --- |
|
|---|
| 59 |
|
|---|
| 60 | ## Options
|
|---|
| 61 |
|
|---|
| 62 | ### preserve
|
|---|
| 63 |
|
|---|
| 64 | The `preserve` option determines whether the original `:any-link` rule is
|
|---|
| 65 | preserved. By default, it is preserved.
|
|---|
| 66 |
|
|---|
| 67 | ```js
|
|---|
| 68 | postcssPseudoClassAnyLink({ preserve: false })
|
|---|
| 69 | ```
|
|---|
| 70 |
|
|---|
| 71 | ```pcss
|
|---|
| 72 | nav :any-link > span {
|
|---|
| 73 | background-color: yellow;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /* becomes */
|
|---|
| 77 |
|
|---|
| 78 | nav :link > span, nav :visited > span {
|
|---|
| 79 | background-color: yellow;
|
|---|
| 80 | }
|
|---|
| 81 | ```
|
|---|
| 82 |
|
|---|
| 83 | ### subFeatures
|
|---|
| 84 |
|
|---|
| 85 | #### areaHrefNeedsFixing
|
|---|
| 86 |
|
|---|
| 87 | The `subFeatures.areaHrefNeedsFixing` option determines if `<area href>` elements should match `:any-link` pseudo-class.<br>
|
|---|
| 88 | In IE and Edge these do not match `:link` or `:visited`.
|
|---|
| 89 |
|
|---|
| 90 | _This increased CSS bundle size and is disabled by default._
|
|---|
| 91 |
|
|---|
| 92 | ```js
|
|---|
| 93 | postcssPseudoClassAnyLink({
|
|---|
| 94 | subFeatures: {
|
|---|
| 95 | areaHrefNeedsFixing: true
|
|---|
| 96 | }
|
|---|
| 97 | })
|
|---|
| 98 | ```
|
|---|
| 99 |
|
|---|
| 100 | ```pcss
|
|---|
| 101 | nav :any-link > span {
|
|---|
| 102 | background-color: yellow;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | /* becomes */
|
|---|
| 106 |
|
|---|
| 107 | nav :link > span, nav :visited > span, area[href] > span {
|
|---|
| 108 | background-color: yellow;
|
|---|
| 109 | }
|
|---|
| 110 | ```
|
|---|
| 111 |
|
|---|
| 112 | [cli-img]: https://github.com/csstools/postcss-plugins/workflows/test/badge.svg
|
|---|
| 113 | [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|---|
| 114 | [css-img]: https://cssdb.org/images/badges/any-link-pseudo-class.svg
|
|---|
| 115 | [css-url]: https://cssdb.org/#any-link-pseudo-class
|
|---|
| 116 | [discord]: https://discord.gg/bUadyRwkJS
|
|---|
| 117 | [npm-img]: https://img.shields.io/npm/v/postcss-pseudo-class-any-link.svg
|
|---|
| 118 | [npm-url]: https://www.npmjs.com/package/postcss-pseudo-class-any-link
|
|---|
| 119 |
|
|---|
| 120 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|---|
| 121 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|---|
| 122 | [PostCSS]: https://github.com/postcss/postcss
|
|---|
| 123 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|---|
| 124 | [PostCSS Pseudo Class Any Link]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-pseudo-class-any-link
|
|---|
| 125 | [Selectors]: https://www.w3.org/TR/selectors-4/#the-any-link-pseudo
|
|---|