I have the following markup:
<div class="c1">
<div class="c2">
<div class="c3">
<input>
<textarea></textarea>
</div>
<input>
<textarea></textarea>
</div>
</div>
I want to match the input and textarea elements from the div.c3 with only one CSS rule. I’m using
div.c1 .c2 .c3 input,textarea { border: 1px solid #f00; }
but this matches all textareas, not only the one cotnained in the c3 div.
Is this possible, or must I write separate CSS selectors for each element?
Look at http://jsfiddle.net/Bp3qn/1/ for the live example.
I updated http://jsfiddle.net/Bp3qn/3/
I only need the input and textarea contained in the c1->c2->c3 containers to be highlighted, not other combinations.
You don’t need the other elements in the selector, unless you only want to match
.c3if it is withindiv.c1 .c2:If you do (per your edit), use this:
Demo: http://jsfiddle.net/wesley_murch/Bp3qn/6/
In that case, to make things easier just add another class to that
.c3like this:Demo: http://jsfiddle.net/wesley_murch/Bp3qn/7/
If you MUST have the selector as small as possible and there are no other children of
.c3.special, just use the star selector (almost never recommended):