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 8.0.15 download and installation detailed tutorial is a must for novices!

This article records the specific steps for downl...

How to install a virtual machine with Windows services on Mac

1. Download the virtual machine Official download...

CSS3 speeds up and delays transitions

1. Use the speed control function to control the ...

How to run Spring Boot application in Docker

In the past few days, I have studied how to run s...

VMware + Ubuntu18.04 Graphic Tutorial on Building Hadoop Cluster Environment

Table of contents Preface VMware clone virtual ma...

A few front-end practice summaries of Alipay's new homepage

Of course, it also includes some personal experien...

A brief discussion of several browser compatibility issues encountered

background Solving browser compatibility issues i...

Let's learn about the MySQL storage engine

Table of contents Preface 1. MySQL main storage e...

MySQL query statement simple operation example

This article uses examples to illustrate the simp...

Detailed explanation of daily_routine example code in Linux

First look at the example code: #/bin/bash cal da...

How to make React components full screen

introduce This article is based on React + antd t...

Linux uses suid vim.basic file to achieve privilege escalation

Reproduce on Kali First set suid permissions for ...

How to disable ads in the terminal welcome message in Ubuntu Server

If you are using the latest Ubuntu Server version...

Security considerations for Windows server management

Web Server 1. The web server turns off unnecessar...