tags:

views:

27

answers:

1

I am trying to select a element with multiple classes.

.parent1 .subparent2 .class1,
.parent1 .subparent2 .class2,
.parent1 .subparent2 .class3 { }

As

.parent1 .subparent2 .class1.class2.class3

to select a element with all three classes but it doesn't work.

Any idea how to do this?

+1  A: 

What you have works, if the browser supports it, you can test it here. Here's my test markup:

<div class="parent1">
    <div class="subparent2">
        <div class="class1 class2 class3">Match</div>
        <div class="class1 class2">No Match</div>
    </div>
</div>​

With your current selector:

.parent1 .subparent2 .class1.class2.class3 { color:red; }​

Based on comments: To be clear, the two selectors are not equivalent, this:

.parent1 .subparent2 .class1, .parent1 .subparent2 .class2 ...

Means that the child can have any of the classes and match, but this:

.parent1 .subparent2 .class1.class2.class3

Means the child has to have all of the classes to match, so they serve different purposes.

Nick Craver
I tried this exactly this does not work. So I am sticking with the first option.
mrNepal
@mrNepal - I think I understand the confusion now, the first and second selectors are not equivalent, the first selects where the child has *any* of the three classes, the `.class1.class2.class3` version means it has to have **all** of the classes, is that what isn't clear?
Nick Craver
Oh yeah, you got it
mrNepal