Home >Web Front-end >CSS Tutorial >How to Style a Checked Radio Button's Label with CSS?
CSS Selector for Labeling Checked Radio Buttons
The question arises: is it possible to style a label associated with a checked radio button using CSS? Despite the expectations, the selector "label:checked" fails to produce the desired result.
A viable solution lies in employing the adjacent sibling combinator " ". This combinator links two sequences of selectors that share a common parent, with the second selector immediately following the first.
For instance, the selector "input[type="radio"]:checked label" targets labels that directly follow checked radio inputs, regardless of their place within the HTML structure.
Example:
input[type="radio"]:checked+label { font-weight: bold; }
HTML:
<input>
This approach effectively boldens the label of the checked radio button while leaving the labels of unchecked buttons unaffected.
The above is the detailed content of How to Style a Checked Radio Button's Label with CSS?. For more information, please follow other related articles on the PHP Chinese website!