Home > Web Front-end > CSS Tutorial > How Can I Style Selected Radio Button Labels with CSS?

How Can I Style Selected Radio Button Labels with CSS?

Patricia Arquette
Release: 2024-12-16 17:27:14
Original
610 people have browsed it

How Can I Style Selected Radio Button Labels with CSS?

Styling Selected Radio Button Labels in CSS

To style the label of a selected radio button, style the label element and use the selector to target the adjacent input[type="radio"] when checked.

HTML Markup

<div class="radio-toolbar">
  <label><input type="radio" value="all" checked>All</label>
  <label><input type="radio" value="false">Open</label>
  <label><input type="radio" value="true">Archived</label>
</div>
Copy after login

CSS

.radio-toolbar input[type="radio"] {
  display: none;
}

.radio-toolbar label {
  display: inline-block;
  background-color: #ddd;
  padding: 4px 11px;
  font-family: Arial;
  font-size: 16px;
  cursor: pointer;
}

.radio-toolbar input[type="radio"]:checked + label {
  background-color: #bbb;
}
Copy after login

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