Sibling + sibling + sibling > child... possible?

I’m looking to apply a style to a child element, when its parent’s target sibling is present

For example, I’ve got three divs A, B & C…

<div class=“a”>stuff</div>
<div class=“b”>stuff</div>
<div class=“c”>stuff<div class=“cc”></div></div>

In this case, I want to apply special formatting to “cc”, only when “a” is present in the markup.

Can I use…

a + b + c > cc {rules…}

I opened up my coding file and from a previous thread I just deleted the code in there, highlighted/deleted etc. It was merely an example anyway.

@OP, your example in your first post didn’t work due to having no content in the child element .cc

And + and > aren’t supported in IE6, I assume the OP knows that if he’s trying this…

Yep. On my first attempt after reading the spec (before posting this question here), I realize now that I was missing a descendent selector, which led me to think it would not work.

Now that I see, and with your helpful example, I’m good. Thanks for the nudge :slight_smile:

Sibling > Child selectors are pretty cool.

Well, why don’t you just try it and find out? :slight_smile:


Transitional//EN" "

<html xmlns="" dir="ltr" 

 <title>OGS Nav</title> 
 <meta http-equiv="Content-Type" content="text/html; 

charset=UTF-8" />
.a + .b + .c .cc{background:red;}
<div class="a">stuff</div>
<div class="b">stuff</div>
<div class="c">stuff<div class="cc">asdf</div></div> 	  

@RyanReese: you have a typo: <base. and your example doesn’t work in ie6.

@Scott Blanchard: this one will:

<html lang="en" dir="ltr"><head>
  <meta	http-equiv="Content-Type"	content="text/html; charset=utf-8">
  <meta	http-equiv="Content-Language"	content="en">
  <title>OGS Nav</title> 
    div div {background:red;} // for ie6
    div + div + div div{background:red;} //for the rest of them

although it’s not what you’ve asked :slight_smile:

just so you know, > selector (selects an element that is a child of another element), + selector (selects an element that is a next sibling of another element) are not supported in ie6.