Home > Web Front-end > CSS Tutorial > How Can I Style Checked Radio Button Labels Using Only CSS?

How Can I Style Checked Radio Button Labels Using Only CSS?

Linda Hamilton
Release: 2024-12-24 16:15:18
Original
791 people have browsed it

How Can I Style Checked Radio Button Labels Using Only CSS?

Styling Checked Radio Button Labels

In CSS, it is possible to apply styles to labels associated with checked radio buttons, even without using additional elements like divs.

The Adjacent Sibling Combinator

To target a label that follows a checked radio button input immediately, use the CSS adjacent sibling combinator ( ). This combinator matches labels that are adjacent to and follow a specific element.

Syntax:

input[type="radio"]:checked + label {
  /* Styles */
}
Copy after login

Example:

Consider the following HTML markup:

<input>
Copy after login

Using the adjacent sibling combinator, you can style the label of the checked radio button as follows:

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

Result:

After selecting a radio button, the corresponding label will become bold, indicating its checked state. This technique can be used with various CSS properties to customize the appearance of checked radio buttons.

The above is the detailed content of How Can I Style Checked Radio Button Labels Using Only 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