CSS ref Selector
From w3cyberlearnings
# | Sector | CSS | Example | Description |
---|---|---|---|---|
1 | .class | 1 | .prod | Selects all elements with class="prod" |
2 | #id | 1 | #age | Selects the element with id="age" |
3 | * | 2 | * | Selects all elements |
4 | element | 1 | p | Selects all <p> elements |
5 | element,element | 1 | div,p | Selects all <div> elements and all <p> elements |
6 | element element | 1 | div p | Selects all <p> elements inside <div> elements |
7 | element>element | 2 | div>p | Selects all <p> elements where the parent is a <div> element |
8 | element+element | 2 | div+p | Selects all <p> elements that are placed immediately after <div> elements |
9 | [attribute] | 2 | [target] | Selects all elements with a target attribute |
10 | [attribute=value] | 2 | [target=_self] | Selects all elements with target="_self" |
11 | [attribute~=value] | 2 | [title~=fruits] | Selects all elements with a title attribute containing the word "fruits" |
12 | [attribute|=value] | 2 | =en] | Selects all elements with a lang attribute value starting with "en" |
13 | :link | 1 | a:link | Selects all unvisited links |
14 | :visited | 1 | a:visited | Selects all visited links |
15 | :active | 1 | a:active | Selects the active link |
16 | :hover | 1 | a:hover | Selects links on mouse over |
17 | :focus | 2 | input:focus | Selects the input element which has focus |
18 | :first-letter | 1 | p:first-letter | Selects the first letter of every <p> element |
19 | :first-line | 1 | p:first-line | Selects the first line of every <p> element |
20 | :first-child | 2 | p:first-child | Selects every <p> element that is the first child of its parent |
21 | :before | 2 | p:before | Insert content before the content of every <p> element |
22 | :after | 2 | p:after | Insert content after every <p> element |
23 | :lang(language) | 2 | p:lang(it) | Selects every <p> element with a lang attribute value starting with "it" |
24 | element1~element2 | 3 | p~ul | Selects every <ul> element that are preceded by a <p> element |
25 | [attribute^=value] | 3 | a[src^="https"] | Selects every <a> element whose src attribute value begins with "https" |
26 | [attribute$=value] | 3 | a[src$=".php"] | Selects every <a> element whose src attribute value ends with ".php" |
27 | [attribute*=value] | 3 | a[src*="woowood"] | Selects every <a> element whose src attribute value contains the substring "woowood" |
28 | :first-of-type | 3 | li:first-of-type | Selects every <li> element that is the first <li> element of its parent |
29 | :last-of-type | 3 | li:last-of-type | Selects every <li> element that is the last <li> element of its parent |
30 | :only-of-type | 3 | li:only-of-type | Selects every <li> element that is the only <li> element of its parent |
31 | :only-child | 3 | li:only-child | Selects every <li> element that is the only child of its parent |
32 | :nth-child(n) | 3 | li:nth-child(2) | Selects every <li> element that is the second child of its parent |
33 | :nth-last-child(n) | 3 | li:nth-last-child(2) | Selects every <li> element that is the second child of its parent, counting from the last child |
34 | :nth-of-type(n) | 3 | li:nth-of-type(2) | Selects every <li> element that is the second <li> element of its parent |
35 | :nth-last-of-type(n) | 3 | li:nth-last-of-type(2) | Selects every <li> element that is the second <li> element of its parent, counting from the last child |
36 | :last-child | 3 | li:last-child | Selects every <li> element that is the last child of its parent |
37 | :root | 3 | :root | Selects the document’s root element |
38 | :empty | 3 | p:empty | Selects every <p> element that has no children (including text nodes) |
39 | :target | 3 | #contents_source:target | Selects the current active #contents_source element (clicked on a URL containing that anchor name) |
40 | :enabled | 3 | input:enabled | Selects every enabled <input> element |
41 | :disabled | 3 | input:disabled | Selects every disabled <input> element |
42 | :checked | 3 | input:checked | Selects every checked <input> element |
43 | :not(selector) | 3 | :not(p) | Selects every element that is not a <p> element |
44 | ::selection | 3 | ::selection | Selects the portion of an element that is selected by a user |