Example of using CSS3 to customize the style of input multiple-select box

Example of using CSS3 to customize the style of input multiple-select box

Principle: First hide the input element, then use CSS to set the style of the label element (other elements can also be used). When selected, use input:check+label to select the label, without using images and JS

Effect Preview

HTML code

 <div class="radio">
    <input type="checkbox" id="sex1">
    <label for="sex1"></label>
    Male
<div class="radio">
    <input type="checkbox" id="sex2">
    <label for="sex2"></label> Female</div>

CSS Code

.radio {
    position: relative;
    display: inline-block;
    margin-right: 12px;
}

.radio input {
    width: 15px;
    height: 15px;
    appearance: none;/*Clear default style*/
    -webkit-appearance: none;
    opacity: 0;
    outline: none;
    z-index: 8; /*Make the input level higher than the label so that it can be selected*/
    
}

.radio label {
    position: absolute;
    left: 0;
    top: 6px;
    width: 15px;
    height: 15px;
    border: 1px solid #3582E9;
}

.radio input:checked+label::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 0px;
    /* Here half of the rectangle is displayed and then rotated 45 degrees to achieve the check mark style*/
    width: 5px;
    height: 12px;
    border-right: 1px solid #000000;
    border-bottom: 1px solid #000000;
    transform: rotate(45deg);
}

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.

<<:  Comprehensive analysis of MySql master-slave replication mechanism

>>:  How to configure multiple projects with the same domain name in Nginx

Recommend

MySQL Database Basics SQL Window Function Example Analysis Tutorial

Table of contents Introduction Introduction Aggre...

Detailed explanation of the difference between $router and $route in Vue

We usually use routing in vue projects, and vue-r...

Detailed explanation of JS array methods

Table of contents 1. The original array will be m...

Solution to EF (Entity Framework) inserting or updating data errors

Error message: Store update, insert, or delete st...

Pure CSS to achieve the water drop animation button in Material Design

Preface You should often see this kind of special...

HTML4.0 element default style arrangement

Copy code The code is as follows: html, address, ...

Detailed explanation of how Node.js middleware works

Table of contents What is Express middleware? Req...

Div adaptive height automatically fills the remaining height

Scenario 1: Html: <div class="outer"...

MySQL database rename fast and safe method (3 kinds)

Table of contents How to rename MySQL database Th...

Detailed explanation of Truncate usage in MySQL

Preface: When we want to clear a table, we often ...

Vue.js implements music player

This article shares the specific code of Vue.js t...

25 CSS frameworks, tools, software and templates shared

Sprite Cow download CSS Lint download Prefixr dow...

Example of using js to natively implement year carousel selection effect

Preface Use js to achieve a year rotation selecti...

Introduction to ufw firewall in Linux

Let's take a look at ufw (Uncomplicated Firew...