Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDominic Hettgen
2,190 PointsCombinators '+' and '>' in pseudo-class :checked
Hi everybody,
I'm doing the css course and I'm wondering why in the code below only the css-selector with the +
-combinator does the job of styling the labels of :checked
radio-buttons.
Why doesn't the >
-combinator work here as well? Apparently the <label>
-tag is a child of <input>
So here's the complete code, I'm confused of. Can anybody help me out? Thanks a lot.
<!DOCTYPE html>
<html>
<head>
<title>UI Element States Pseudo-Classes</title>
<link rel="stylesheet" href="css/style.css">
<style>
input[type="radio"]:checked + label {
background-color: tomato;
}
</style>
</head>
<body>
<form>
<input type="text" name="name" placeholder="name">
<input type="text" name="email" placeholder="email" disabled>
<div>
<input disabled name="radio" id="radio1" type="radio"><label for="radio1">Option 1</label>
<input name="radio" id="radio2" type="radio"><label for="radio2">Option 2</label>
<input name="radio" id="radio3" type="radio"><label for="radio3">Option 3</label>
</div>
<input type="submit" name="submit">
</form>
</body>
</html>
2 Answers
Katarzyna Fijolek
14,494 PointsThis is because label is not a child of input, it is its sibling. Notice how input (just like <br> for example) doesn't have a closing tag, so label is not actually contained between <input></input>. I hope this helps, I tried to do my best explaining this, but I'm not best at explaining things ;)
Dominic Hettgen
2,190 PointsGot it. It's because of the missing closing tag. Thank you so much.
Katarzyna Fijolek
14,494 PointsNo problem :). I'm glad I could be of help