-4

Is there a difference between these?

.someClass.anotherClass

.someClass .anotherClass

Does the white space make a difference. If yes, what difference does it make?

Rohan
  • 13,308
  • 21
  • 81
  • 154
  • 2
    ...It would take maximally one minute to create a test on your own. I bet you'd find the answer without much difficulties. This question is also already covered here on SO. – Roko C. Buljan Oct 20 '14 at 10:39

3 Answers3

4

Yes it makes a difference. Using a space is the descendant selector. In your example, anotherClass must be a descendant of someClass.

<div class="someClass">
    <div class="anotherClass"></div>
</div>

Without a space, you are targeting elements that match all classes specified. In your example, matched elements must have both someClass and anotherClass.

<div class="someClass anotherClass">
</div>
MrCode
  • 63,975
  • 10
  • 90
  • 112
  • 1
    They are called [combinators](http://www.w3.org/TR/css3-selectors/#combinators), not selectors now. – Quentin Oct 20 '14 at 10:53
0

.someClass.anotherClass will select below element

<div class="someClass anotherClass"></div>

.someClass .anotherClass (descendant selector)

<div class="someClass">
<span class="anotherClass"></span> //this will be selected
</div>
Shoaib Chikate
  • 8,665
  • 12
  • 47
  • 70
0

.someClass.anotherClass will work in the case of if your class name is "someClass anotherClass", Means you have only one class including space between name.

.someClass .anotherClass It will not affect to your first class['someClass'] code if you have two different classes. Only second class with be affected.

Hope u will get the point.

Sanjay Soni
  • 201
  • 1
  • 13