Home Web Front-end CSS Tutorial Use CSS to customize the style of the green checkbox button

Use CSS to customize the style of the green checkbox button

Jun 12, 2018 am 09:51 AM
css checkbox button

This article mainly introduces the style of CSS custom green check box button, which has certain reference value. Now I share it with you. Friends in need can refer to

HTML’s own complex The select box or radio button button styles are relatively simple. Sometimes these form controls may need to match their own theme styles. They need to beautify them. In the past, you may need to use JS to implement it. Now CSS can also be fully implemented The effect we want.

Rendering:

Let’s go straight to the topic. The first thing that comes to mind is that the check box needs a background color. Then there is a check box selected state. We use "check mark" to represent the selected state here. HTML can simply represent

<p class="i-check">
       <input type="checkbox" value="0" />
       <label></label>
</p>
Copy after login

.i-check as a whole check box. Added CSS The code is also simple

.i-check {   
    width: 20px;   
    height: 20px;   
    position: relative;   
    margin: 20px auto;   
}
Copy after login

The size of the check box is determined according to your own needs. The margin is set here to display it in the middle of the browser.
Then the default state of the check box is set, here Use label to set, its height and width are the same as .i-check settings, then give it a background color and set its position.

.i-check label {   
   width: 20px;   
   height: 20px;   
   cursor: pointer;   
   position: absolute;   
   top: 0;   
   left: 0;   
   background: #1A9909;   
   border-radius: 4px;
Copy after login

We have already fixed the default state. Let's continue the analysis, What is needed at this time is a selected state. As mentioned above, the selected state is represented by a check mark. Here we use the pseudo-class after to set it, set its border, and rotate the after, so that it becomes a check mark. But the default state The check mark is hidden, so we used an opacity of 0.

.i-check  label:after {   
    content: &#39;&#39;;   
    width: 9px;   
    height: 5px;   
    position: absolute;   
    top: 4px;   
    left: 4px;   
    border: 3px solid #fff;   
    border-top: none;   
    border-right: none;   
    background: transparent;   
    opacity: 0;   
    transform: rotate(-45deg);   
}
Copy after login

Okay, the entire state is set. Now we need to make the check mark appear when the check box is clicked. The following code will do it Complete

.i-check input[type=checkbox]:checked + label:after {   
    opacity: 1;   
}
Copy after login

After writing this, don’t forget to let the Input check box set its style. In order to allow users to click on it, its height and width must be the same size as the whole box, so that it is at the top of the entire box. The top level. This way the user can click anywhere in this area. OK, the last step is to hide the input checkbox. To hide it, it is not to actually hide it and remove it. In this case, there will be no click effect. Hide here What is needed is to use opacity to set it to 0.

.i-check input[type=checkbox] {   
    opacity: 0;   
    position: absolute;   
    z-index: 2;   
    left: 0;   
    top: 0;   
    width: 100%;   
    height: 100%;   
    margin: 0;   
}
Copy after login

Okay, the entire effect is completed. In the same way, you can also set the effect of the radio button.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Two methods to use CSS to implement the code that the size of the background image does not change with the browser zoom

How to set CSS Text font color

#How to solve the problem of gaps under CSS images

The above is the detailed content of Use CSS to customize the style of the green checkbox 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 use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

See all articles