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

Detailed tutorial on running Tomcat in debug mode in IDEA Maven project

1. Add the following dependencies in pom.xml <...

Detailed explanation of JDBC database link and related method encapsulation

Detailed explanation of JDBC database link and re...

Example code for implementing 3D text hover effect using CSS3

This article introduces the sample code of CSS3 t...

The 6 Most Effective Ways to Write HTML and CSS

This article shares the 6 most effective methods,...

Complete steps for using Nginx+Tomcat for load balancing under Windows

Preface Today, Prince will talk to you about the ...

Comprehensive understanding of html.css overflow

Comprehensive understanding of html.css overflow ...

An example of using Dapr to simplify microservices from scratch

Table of contents Preface 1. Install Docker 2. In...

Docker Stack deployment method steps for web cluster

Docker is becoming more and more mature and its f...

Summary of the characteristics of SQL mode in MySQL

Preface The SQL mode affects the SQL syntax that ...

Vue development tree structure components (component recursion)

This article example shares the specific code of ...

How to implement property hijacking with JavaScript defineProperty

Table of contents Preface Descriptors Detailed ex...

Detailed explanation of Linux copy and paste in VMware virtual machine

1. Linux under VMware Workstation: 1. Update sour...

Should the Like function use MySQL or Redis?

Table of contents 1. Common mistakes made by begi...