CSS Selectors Flashcards
Combining selectors?
h1, h2, h3, h5{
font-family: sans-sarif;
}
Descended selector?
footer p{
font-size: 13px;
}
Descended selector: The p element is in the footer element
Only applies to that <p> element
</p>
Refers to id
#
Refers to class - Class can be used more than once, preferred method
.related
Pseudo class syntax?
li:first-child{}
First-child is an example of a pseudo class since it does not exist in the HTML
A list of pseudo classes can be found on the MDN reference page
Pseudo class reference last child
li:last-child{}
Pseudo class reference second entry
li:nth-child(2){}
Pseudo class reference odd entries in list
li:nth-child(odd){}
What does it do?
article p: first-child{}
This would not do anything at all.
Rather use: article : first-child{}
What modes can we use for anchor element?
+ syntax
+ order
a{} Style link
ALWAYS USE THIS ORDER:
a:link{} Styling the link, overrides previous
a:visited{} If it has been visited
a:hover{}
a:active{} If it is being pressed
Chaining pseudo classes and refer to last child only
nav a:link:last-child{}
‘Link’ here is the first state of the anchor element. It refers here to the last element of all anchor tags within the nav tag.
nav
<a>Blog</a>
<a>Challenges</a>
<a>Flexbox</a>
<a>CSS Grid</a>
nav
Pseudo element first letter
Pseudo elements
It is possible to refer to just the first letter in an element with pseudo elements, you write the pseudo element with ::
h1::first-letter{}
Pseudo element first line
p::first-line{}
You can highlight the complete first line of a paragraph for example
This is how you refer to a pseudo element within a sibling
h3 + p::first-line{}
When there’s a < p > element straight after an < h3 > element it will color the first line of that < p > element
Places the content straight after the last child within that element, so in this after the last character in h2
h2::after{}