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{}
Pseudo element absolute positioning
h2::after{}
Set the h2 pseudo element to position:absolute
h2{}
Set h2 element to relative. This way you can position the pseudo element relative to the main element
What happens when not using absolute positioning in pseudo element?
h2::before{
position:absolute
….
}
h2{
position:relative
}
When not using absolute positioning, the element will be placed before the text
What does this do?
article :first-child {
color: red;
}
Code looks at sibling childs of article. This could be anything: < p >, < li >, etc
It then addresses the FIRST CHILD OF THOSE SIBLING childs and paints them red. This could be first letter italic text < em > or bold text < strong > within that <p> element in the article.
Or a first list entry of the lists within that article for example</p>
Set hover pseudo class on button
.button:hover {
color: #000;
background-color: #fff;
}
What does ::before do?
In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
What to do when needing a global reset (0px margin and padding)?
*{
margin:0px;
padding:0px
}
Problem: When having two consecutive grids and you want margin-bottom so you can split them, the margin will be added to all grids which you don’t want. How to resolve?
Set
.grid:last-child{margin bottom: 0}
Or
.grid:not(:last-child){margin bottom: 9.6rem}