source: frontend/node_modules/css-has-pseudo/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.9 KB
Line 
1# CSS Has Pseudo [<img src="http://jonathantneal.github.io/js-logo.svg" alt="" width="90" height="90" align="right">][CSS Has Pseudo]
2
3[![NPM Version][npm-img]][npm-url]
4[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
5
6[CSS Has Pseudo] lets you style elements relative to other elements in CSS,
7following the [Selectors Level 4] specification.
8
9[!['Can I use' table](https://caniuse.bitsofco.de/image/css-has.png)](https://caniuse.com/#feat=css-has)
10
11```css
12a:has(> img) {
13 /* style links that contain an image */
14}
15
16h1:has(+ p) {
17 /* style level 1 headings that are followed by a paragraph */
18}
19
20section:not(:has(h1, h2, h3, h4, h5, h6)) {
21 /* style sections that don’t contain any heading elements */
22}
23
24body:has(:focus) {
25 /* style the body if it contains a focused element */
26}
27```
28
29## Usage
30
31From the command line, transform CSS files that use `:has` selectors:
32
33```bash
34npx css-has-pseudo SOURCE.css --output TRANSFORMED.css
35```
36
37Next, use your transformed CSS with this script:
38
39```html
40<link rel="stylesheet" href="TRANSFORMED.css">
41<script src="https://unpkg.com/css-has-pseudo/dist/browser-global.js"></script>
42<script>cssHasPseudo(document)</script>
43```
44
45⚠️ Please use a versioned url, like this : `https://unpkg.com/css-has-pseudo@3.0.0/dist/browser-global.js`
46Without the version, you might unexpectedly get a new major version of the library with breaking changes.
47
48⚠️ If you were using an older version via a CDN, please update the entire url.
49The old URL will no longer work in a future release.
50
51That’s it. The script is 765 bytes and works in most browser versions, including
52Internet Explorer 11. With a [Mutation Observer polyfill], the script will work
53down to Internet Explorer 9.
54
55See [README BROWSER](README-BROWSER.md) for more information.
56
57## How it works
58
59The [PostCSS plugin](README-POSTCSS.md) clones rules containing `:has`,
60replacing them with an alternative `[:has]` selector.
61
62```css
63body:has(:focus) {
64 background-color: yellow;
65}
66
67section:not(:has(h1, h2, h3, h4, h5, h6)) {
68 background-color: gray;
69}
70
71/* becomes */
72
73body[\:has\(\:focus\)] {
74 background-color: yellow;
75}
76
77body:has(:focus) {
78 background-color: yellow;
79}
80
81section[\:not-has\(h1\,\%20h2\,\%20h3\,\%20h4\,\%20h5\,\%20h6\)] {
82 background-color: gray;
83}
84
85section:not(:has(h1, h2, h3, h4, h5, h6)) {
86 background-color: gray;
87}
88```
89
90Next, the [JavaScript library](README-BROWSER.md) adds a `[:has]` attribute to
91elements otherwise matching `:has` natively.
92
93```html
94<body :has(:focus)>
95 <input value="This element is focused">
96</body>
97```
98
99[discord]: https://discord.gg/bUadyRwkJS
100[npm-img]: https://img.shields.io/npm/v/css-has-pseudo.svg
101[npm-url]: https://www.npmjs.com/package/css-has-pseudo
102
103[CSS Has Pseudo]: https://github.com/csstools/postcss-plugins/tree/main/plugins/css-has-pseudo
104[Mutation Observer polyfill]: https://github.com/webmodules/mutation-observer
105[Selectors Level 4]: https://drafts.csswg.org/selectors-4/#has-pseudo
Note: See TracBrowser for help on using the repository browser.