Consider this HTML with CSS classes aa, bb and cc:
<div class='aa'>
<div class='bb'>
<div class='cc'>
</div>
</div>
</div>
I can select the class=cc
tag like so: .aa > .bb > .cc
. However, in my case, sometimes the .bb
tag is absent, that is, the HTML looks like so:
<div class='aa'>
<div class='cc'>
</div>
</div>
Thererfore, to select all .cc
close to an .aa
, I'd need to specify two CSS paths:
.aa > .bb > .cc,
.aa > .cc { .... }
This works, but, is there no shorter way? Something similar to this:
.aa > (.bb >)? .cc { ... } /* ? means "optional" */
with CSS or something like Stylus or LESS?
Motivation: In the real world, "aa" and "bb" and "cc" are somewhat longer names, and there's more stuff before and after the "aa" and "cc", and it'd be nice to not need to duplicate that stuff.
Please note: In my case, this won't work: .aa .cc
because that'd match too many .cc
s elsewhere on the page. The .cc
s need to be either immediately below the .aa
, or below .aa > .bb
.
.aa .cc
is too general because you don't want to match.cc
elements that are more distant descendants of.aa
elements, then I think the.aa > .bb > .cc, .aa > .cc
selector you already mentioned is best. – Mania.bb
and.cc
the only two possible children of.aa
? – Depositary.aa
has other children too. (What did you have in mind, if the answer had been yes?) – Musketry.aa > .cc, .aa > * > .cc
. Doesn't do much, but it would allow you to skip typing.bb
... – Depositary