When should I be using this:
header.classname
and when should I use this:
header .classname
And what is the difference between the two?
When should I be using this:
header.classname
and when should I use this:
header .classname
And what is the difference between the two?
header.classname
mean you are targeting header having class as classname
.
header .classname
mean you are targeting the html element having class classname
which is a child/descendent of header
1st case:
header.hclassname {
background: turquoise;
}
<header class="hclassname">
Lorem Ipsum
<div class="divclassname">Dolor</div>
Sit Amet
</header>
2nd case
header .divclassname {
background: skyblue;
}
<header class="hclassname">
Lorem Ipsum
<div class="divclassname">Dolor</div>
Sit Amet
</header>
Use header.classname
when: you want to target a .classname
that is a header
element.
Use header .classname
when: you want to target .classname
descendants of a header
element.
I hope this solves your question, it's as simple as can be.