Home > Web Front-end > CSS Tutorial > How to customize checkbox style with css? (code example)

How to customize checkbox style with css? (code example)

青灯夜游
Release: 2018-10-11 15:11:13
forward
2792 people have browsed it

How to customize checkbox style in css? This article will introduce to you how to use css to modify the native checkbox style and customize the checkbox style. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Let’s take a look at the effect first

How to customize checkbox style with css? (code example)

Principle

1. Use the CSS3 attribute appearance .

This attribute (forced) changes (changes) the default (native) style.

Firefox supports the alternative -moz-appearance attribute; Safari and Chrome support the alternative -webkit-appearance attribute; IE does not support this attribute.

So you can use this attribute to cancel the native style of the checkbox.

2. Use:checked selector

Change the style when the checkbox is selected.

3. :after selector content attribute

:The after selector inserts content after the element.

We can then use text-aligen and line-height to center the content.

Example code:

nbsp;html>
    <meta>
    <title>checkbox</title>
    <style>
        input {
            width: 16px;
            height: 16px;
            margin-top: 0;
            background-color: #fff;            
            border: 1px solid #c9c9c9;
            border-radius: 2px;
            color: #fff;
            text-align: center;
            line-height: 15px;
            -webkit-appearance:none;
            -moz-appearance:none;
            -ms-appearance:none;
            -o-appearance:none;
            appearance:none;
            outline: none;
        }

        input:hover {
            border-color: #43adea;
        }

        input:checked {
            color: #fff;
            background-color: #43adea;
            border: 1px solid #43adea;
        }

        input:after {
            content: "✔";
        }
    </style>
    <input>
    <input>
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more related tutorials, please visit CSS Video Tutorial!

Related recommendations:

php public welfare training video tutorial

CSS Online Manual

##div/css graphic tutorial

The above is the detailed content of How to customize checkbox style with css? (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template