What I have is a form with one fieldset containing several other fieldsets. For each fieldset, the user can check a box next to the legend and expand that fieldset (in theory, at least). I was thinking it would be cool to try using pure CSS for the effect, but I'm getting hung up on how to write the rule based on the two elements position to one another in the DOM. Here's the HTML:
<fieldset id="areasofinterest">
<legend>Areas of Interest Survey</legend>
<p>Please Check The Areas Applicable to you and Answer the Coorepsonding Questions.</p>
<!--Area 1 Checkbox and Questions -->
<fieldset class="area">
<legend>
<input type="checkbox" value="area1" id="area1" />
<label for="area1"> Area 1 :</label>
</legend>
<ul>
<li>
<label for="area1_q1">Q1</label>
<input type="text" name="area1_q1" id="area1_q1" />
</li>
<li>
<label for="area1_q2">Q2</label>
<input type="text" name="area1_q2" id="area1_q2" />
</li>
</ul>
</fieldset>
<!--Area 2 Checkbox and Questions -->
<fieldset class="area">
<legend>
<input type="checkbox" value="area2" id="area2" />
<label for="other"> Area 2 :</label>
</legend>
<ul>
<li>
<label for="area2_q1">Q1</label>
<input type="text" name="area2_q1" id="area2_q1" />
</li>
<li>
<label for="area2_q2">Q2</label>
<input type="text" name="area2_q2" id="area2_q2" />
</li>
</ul>
</fieldset>
</fieldset>
At first the idea seemed a bit hack-ish to me, but I ran it through the w3c validator, and yipiee it passed with inputs embedded within legends. So I'm sure I can get what I'm after using javascript/jquery, but I'd hate to at least have a proof of concept for doing it with CSS, even if older browsers may not support it.
I tried this rule:
.area ul {
color: red;
}
.area input:checked + ul {
color: blue;
}
But with no luck. I confirmed with a much simpler test that both browsers I'm working with (Chrome, FF 3.5) can do input:checked + ul
if it's simply an input followed by a ul. And it does toggle colors if I have both rules (in the simplified version).
But I'm not sure if there is a way to refer to the UL if the checked element is whithin the legend tag and thus not a direct sibling of the UL. Is there maybe a way to say "siblings of legends which contain inputs which are checked..."?
Thanks for the help.