3

When should I be using this:

header.classname

and when should I use this:

header .classname

And what is the difference between the two?

Omar
  • 51
  • 8
  • 2
    Even though there is nothing wrong with posting this question here, I do suggest following a CSS starter tutorial. It'll get you through the basics and most tutorials teach you stuff like this as well. I've heard good things about http://codecademy.com, but you could also try http://csstutorial.net, or the infamous w3schools css tutorial. Or have a go at google to find one in whatever language and style you want. (get it, style?) – Joeytje50 Sep 05 '16 at 04:18
  • The difference is what the documentation says it is. –  Sep 05 '16 at 04:33

2 Answers2

8

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>
Praveen
  • 827
  • 6
  • 14
2

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.

ifvictr
  • 141
  • 2
  • 3
  • 13