1

I know when there is a space in between, it will look for the class on the right within the class on the left.

.classA .classB {
    ...
}

However, what does it look for when there is no space?

.classA.classB {
    ...
}
War10ck
  • 12,387
  • 7
  • 41
  • 54
obai
  • 399
  • 5
  • 14
  • 3
    An element which contains both classes. Read here: http://stackoverflow.com/questions/5116288/css-select-an-element-with-2-class – Adam Fratino Oct 08 '14 at 17:40
  • 1
    @88MPG - You should post it as an answer... – LcSalazar Oct 08 '14 at 17:42
  • @LcSalazar I'm sure 50 answers will pop up by the time I post one. – Adam Fratino Oct 08 '14 at 17:43
  • possible duplicate of [CSS Selector that applies to elements with two classes](http://stackoverflow.com/questions/3772290/css-selector-that-applies-to-elements-with-two-classes), [http://stackoverflow.com/questions/3918742/css-styling-when-element-has-two-classes](http://stackoverflow.com/questions/3918742/css-styling-when-element-has-two-classes), [http://stackoverflow.com/questions/5796654/css-rule-to-apply-only-if-element-has-both-classes](http://stackoverflow.com/questions/5796654/css-rule-to-apply-only-if-element-has-both-classes)... – War10ck Oct 08 '14 at 17:43
  • @88MPG - If you had posted it by the time you posted the comment, you would be upvoted instead of answers popping up... – LcSalazar Oct 08 '14 at 17:45
  • @LcSalazar You're right, I posted an answer with some syntax examples and references. – Adam Fratino Oct 08 '14 at 17:47
  • Thanks all for the quick reply – obai Oct 08 '14 at 18:36
  • @War10ck - agree that those posts are about same topic. However, those posts are asking the question from the other direction. In other words, they are asking how to do something, whereas my question was, I found something in the code but I don't know what it is doing. – obai Oct 08 '14 at 18:50

3 Answers3

3

The first example (space-separated classes) is a parent-child relationship. .classB is found inside .classA.

<div class="classA">
    <div class="classB"></div>
</div>

The second is for one element with multiple classes, like so:

<div class="classA classB"></div>

Very different situations, but both extremely useful!

Further reading here:
css select an element with 2 class
http://css-tricks.com/multiple-class-id-selectors/

Community
  • 1
  • 1
Adam Fratino
  • 1,245
  • 10
  • 23
1

It's used when you need an element, with both classes.

<div class="classA classB"></div>

would match

.classA.classB{}

See also:
http://css-tricks.com/multiple-class-id-selectors/

Frederik Spang
  • 3,379
  • 1
  • 25
  • 43
1

In the first example .classA .classB you're selecting elements with the class classB that are descendants of elements that have classA.

In the second example .classA.classB you're selecting elements that have both classes classA and classB.

j08691
  • 204,283
  • 31
  • 260
  • 272