Home > Web Front-end > CSS Tutorial > How to Style a Checked Radio Button's Label with CSS?

How to Style a Checked Radio Button's Label with CSS?

Barbara Streisand
Release: 2024-12-29 00:20:13
Original
790 people have browsed it

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; }
Copy after login

HTML:

<input>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template