It's interesting how the behavior is affected by the relationship between the <p>
and input elements, with one being siblings and not children of the other. I found a workaround where you wrap each input
and p
block in a div
, and then use the ~
selector...
Here's the CSS:
input:checked ~ p + p {
color: red;
}
And here's the HTML:
<div>
<input type="radio" name="accordion" checked />
<p>Paragraph one</p>
<p>Paragraph two</p>
</div>
<div>
<input type="radio" name="accordion" />
<p>Paragraph three</p>
<p>Paragraph four</p>
</div>
Check out the demo here.
UPDATE:
I noticed that adding this CSS to the original HTML also makes it work. The second selector style being empty doesn't seem to affect it, though...
input:checked + p + p {
color: red;
}
p:nth-child(2){}