Home Web Front-end CSS Tutorial Use the :checked pseudo-class selector to change the style of a selected checkbox or radio button

Use the :checked pseudo-class selector to change the style of a selected checkbox or radio button

Nov 20, 2023 am 11:48 AM
style selector :checked

Use the :checked pseudo-class selector to change the style of a selected checkbox or radio button

Because the length of the article is limited, there are only short code examples. Here is an example:

Suppose we have the following HTML structure:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Checked伪类选择器示例</title>
  <style>
    input[type="checkbox"]:checked + label {
      font-weight: bold;
      color: green;
    }
  </style>
</head>
<body>
  <input type="checkbox" id="checkbox1">
  <label for="checkbox1">选项1</label>
  <input type="checkbox" id="checkbox2">
  <label for="checkbox2">选项2</label>
</body>
</html>
Copy after login

In the above example, input[type="checkbox"]:checked label is used Selector, when the check box is selected, the style of the adjacent label element will change, becoming bold and green.

The above is the detailed content of Use the :checked pseudo-class selector to change the style of a selected checkbox or radio button. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to modify element.style How to modify element.style Nov 24, 2023 am 11:15 AM

Methods for element.style to modify elements: 1. Modify the background color of the element; 2. Modify the font size of the element; 3. Modify the border style of the element; 4. Modify the font style of the element; 5. Modify the horizontal alignment of the element. Detailed introduction: 1. Modify the background color of the element, the syntax is "document.getElementById("myElement").style.backgroundColor = "red";"; 2. Modify the font size of the element, etc.

How to dynamically modify style in react How to dynamically modify style in react Dec 28, 2022 am 10:44 AM

Methods for react to dynamically modify style: 1. Add ref to the element whose style needs to be modified, with syntax such as "<div className='scroll-title clear-fix' ref={ this.manage }>"; 2. Through dynamic control The change of state modifies the style of the element; 3. By using JS code in the DOM, the display and hiding transitions of different DOMs are realized.

What are the new features in Vue3 style and how to use them What are the new features in Vue3 style and how to use them May 14, 2023 pm 10:52 PM

New features of style Vue3.2 version has made many upgrades to the style of single-file components, such as local styles, css variables, and styles exposed to templates. (Learning video sharing: Vue video tutorial) 1. Local style When the label has scoped attribute, its CSS will only be applied to the elements of the current component: hi.example{color:red;} 2. The depth selector is scoped If the selector in the style wants to make a more "deep" selection, that is, affect sub-components, you can use the :deep() pseudo-class: .a:deep(.b){/*...*/ }DOM content created through v-html will not be

How to implement the IO model and Selector of Java underlying technology How to implement the IO model and Selector of Java underlying technology Nov 08, 2023 pm 06:00 PM

Implementing the IO model and Selector of Java's underlying technology In Java programming, the IO (Input-Output) model and Selector are very important underlying technologies. They are crucial for efficiently processing network communication and file operations. In this article, we will delve into the implementation principles of the IO model and Selector in Java, and provide specific code examples to help readers better understand these concepts. 1. IO model blocking IO blocking IO model is the most basic type of I

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Aug 26, 2023 pm 10:58 PM

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? In Vue development, we often use the v-bind instruction to dynamically bind class and style, but sometimes we may encounter some problems, such as being unable to correctly use v-bind to bind class and style. In this article, I will explain the cause of this problem and provide you with a solution. First, let’s understand the v-bind directive. v-bind is used to bind V

How to select the channel in java's Selector How to select the channel in java's Selector May 04, 2023 pm 12:40 PM

1. Multiple SelectableChannels can be managed through Selector. Its select() method can monitor which channels are ready for I/O operations. The return value represents the number of these I/Os. intselect() intselect(longtimeout) intselectNow() 2. When the select() method is called, it will save the SelectionKey representing the channel that is ready for I/O operations in a collection, which can be returned through selectedKeys(). The three methods of SetselectedKeys()select() can be seen from the naming.

Use the :checked pseudo-class selector to change the style of a selected checkbox or radio button Use the :checked pseudo-class selector to change the style of a selected checkbox or radio button Nov 20, 2023 am 11:48 AM

Because the article is of limited length, only brief code examples are included. Here's an example: Suppose we have the following HTML structure: &lt;!DOCTYPEhtml&gt;&lt;htmllang="en"&gt;&lt;head&gt;&lt;metacharset="UTF-8"&gt;&lt;metaname="viewpo

How to use class and style binding arrays to implement multiple bindings in Vue How to use class and style binding arrays to implement multiple bindings in Vue Jun 11, 2023 pm 01:29 PM

Vue is a popular JavaScript framework often used to build interactive web applications. In Vue, class and style binding are two common concepts used to style page elements. Similar to CSS, they can modify the appearance of single or multiple elements through selectors. However, in Vue, class and style bindings allow you to use arrays as values, thus enabling multi-binding. This article will explore how to use class and style to bind array implementations in Vue

See all articles