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
Patricia ArquetteOriginal
2024-12-16 17:27:14616browse

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>

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;
}

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!

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