1 | h1, h2{ |
The ID Selector
https://coolors.co/palettes/trending
1 | #lagout{ |
The class Selector
1 | <a class="tag" href="#puppies">Puppies</a> |
1 | .tag{ |
Descendant Selector
1 | li a{ |
Adjacent Selector
1 | h1 + p{ |
Select only the paragraphs that are immidiately preceded by an <h1>
Direct Child
1 | div > li{ |
Select only the <li>
‘s that are direct children of a <div>
element
Attribute Selector
Select all input elements where the type attribute is set to “text”
1 | input[type="text"]{ |
1 | a[href*="google"]{ |
class
is one attribute, so asid
.
href*=”google” - Fuzzier matching
PSEUDO classes
keyword added to a selector that specifies a special state of the selected element(s)
- :active
- :checked
- :first
- :first-child
- :hover
- :not()
- :nth-child()
- :nth-of-type()
https://developer.mozilla.org/en-US/docs/Web/CSS/:hover
PSEUDO ELEMENTS
Keyword added to a selector that lets you style a particular part of selected element(s)
- ::after
- ::before
- ::first-letter
- ::first-line
- ::selection
SPECIFICITY
Specificity is how the brower decides which rules to apply when multiple rules could apply to the same element. It is a measure of how specific a given selector is. The more specific selector “wins”.
1 | ID > Class > Element |
How to calculate the importance
- ID selector: 100
- Class, Attribute, Pseudo-Class, Selectors: 10
- Element, Pseudo-Element, Selectors: 1
The combination of the things above:
For example
1 | nav a.active{ |
0*100+1*10+2*1
https://specificity.keegan.st/
!important
tag is superb every calculation above.
CSS Inheritance
1 | button{ |