Pure CSS implementation of radio and checkbox effect example

Pure CSS implementation of radio and checkbox effect example

radio-and-checkbox

Pure CSS to achieve radio and checkbox effects

reset-radio

When developing PC projects, radio and checkbox components are often used. However, because the native styles are relatively inconsistent with the designer's design style, we may often reference third-party modules to implement them, or hack them through other methods such as JS. This not only increases the amount of code, but is also very complicated, so there is this pure CSS implementation that relies on native input[radio] and input[checkbox]. The main code is as follows:

HTML main code

<div class="reset-radio">
    <input checked type="radio" id="age1" name="age">
    <span class="real-target"></span>
</div>

CSS code, here mainly through a child node span to cooperate with the input: checked brother selector to modify the style

.reset-radio {
    display: inline-block;
    position: relative;
    width: 16px;
    height: 16px;
}

.reset-radio .real-target {
    z-index: 1;
    width: 100%;
    height: 100%;
    position: absolute;
    display: inline-block;
    background: #ffffff;
    border: 1px solid #dadde0;
    border-radius: 100%;
    top: 0;
    left: 0;
    bottom: 0;
}

.reset-radio input[type=radio] {
    cursor: pointer;
    z-index: 2;
    width: 16px;
    height: 16px;
    opacity: 0;
    position: absolute;
    left: 0;
    top: 0;
    margin: 0;
    right: 0;
    bottom: 0;
}

.reset-radio input:checked+span {
    border-color: #48b4ec;
}

.reset-radio input:checked+span::before {
    content: '';
    position: absolute;
    background: #48b4ec;
    width: 6px;
    height: 6px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 100%;
}

reset-checkbox

The principle of reset-checkbox is the same, so I won't go into details.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Definition and usage of MySQL cursor

>>:  Brief analysis of the introduction and basic usage of Promise

Recommend

Configure Mysql master-slave service implementation example

Configure Mysql master-slave service implementati...

Steps to change mysql character set to UTF8 under Linux system

Table of contents 1. Check the MySQL status in th...

Introduction to Computed Properties in Vue

Table of contents 1. What is a calculated propert...

JavaScript timer to achieve limited time flash sale function

This article shares the specific code of JavaScri...

Summary of SQL deduplication methods

When using SQL to extract data, we often encounte...

Detailed explanation of MySQL database triggers

Table of contents 1 Introduction 2 Trigger Introd...

Detailed analysis of MySQL master-slave delay phenomenon and principle

1. Phenomenon In the early morning, an index was ...

How to set background blur with CSS

When making some pages, in order to make the page...

URL Rewrite Module 2.1 URL Rewrite Module Rule Writing

Table of contents Prerequisites Setting up a test...

Use CSS3 to implement button hover flash dynamic special effects code

We have introduced how to create a waterfall layo...

Vue-Element-Admin integrates its own interface to realize login jump

1. First look at the request configuration file, ...

js to realize a simple advertising window

This article shares the specific code of js to im...

An article to teach you HTML

If you are not committed to becoming an artist, t...