Home >Web Front-end >CSS Tutorial >How can I style labels of checked radio buttons using CSS?

How can I style labels of checked radio buttons using CSS?

Linda Hamilton
Linda HamiltonOriginal
2024-12-21 08:19:13313browse

How can I style labels of checked radio buttons using CSS?

Styling Labels of Checked Radio Buttons with CSS

The task of applying CSS styles to labels associated with checked radio buttons can be accomplished using the CSS selector 'input[type="radio"]:checked label`.

Explanation:

The ` symbol in this selector represents the **Adjacent Sibling Combinator**. It ensures that the label appears immediately after the checked radio button input. By combining this selector with the :checked` pseudo-class, it targets labels that follow checked radio button inputs.

For example, consider the following markup:

<input>

Using the selector `input[type="radio"]:checked label, you can apply the following style:

input[type="radio"]:checked+label {
  font-weight: bold;
}

This style will make the label of the checked radio button bold, while leaving the labels of unchecked radio buttons unchanged.

The above is the detailed content of How can I style labels of checked radio buttons using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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