Is there a difference between these?
.someClass.anotherClass
.someClass .anotherClass
Does the white space make a difference. If yes, what difference does it make?
Is there a difference between these?
.someClass.anotherClass
.someClass .anotherClass
Does the white space make a difference. If yes, what difference does it make?
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>
.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>
.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.