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 trialSaqib Ishfaq
13,912 Pointswhy is it that we have to specify more, after having specified the type attribute already
that <input> is the next sibling to <label> and when that is :checked { this should happen }
2 Answers
Zack Lee
Courses Plus Student 17,662 Pointsthe reason the selector is so long is because your defining a "path" to the tag you want. Check boxes are interesting because they have a state called checked. When a checkbox if checked you can define a selector that will effect an element other than the checkbox.
so in this example, we first reference the input with type checkbox, then we use a psuedo-class to specify that the properties are active when checked. then we use a sibling selector to specify that these properties are for the label sibling of the checkbox.
you can read the selector like this:
+ label //select the sibling label
input[type=checkbox]:checked //when the input checkbox is checked
//put it all together
input[type=checkbox]:checked + label {...} //when the checkbox is checked, select the label
so now, when the checkbox element is checked, this selector specifies the properties that change on the label. Css-tricks has some great articles on checkboxes you should check out.
JASON LEE
17,352 PointsI was confused with the same thing. Then I realized I was looking at the label that had the innerHTML "Interests:" and didn't see the labels that were on the same line of code as the checkbox. The latter label is what it is referring to.