How to change the default checkbox style

Source: Internet
Author: User
when we use a checkbox to the input label in a project, its default style usually does not meet the requirements of the project, mainly because it looks a little ugly. To change it according to the needs of the project is what we want to do, the following two common practice.

1. Use background picture instead of selected effect
The main principle is to hide the original checkbox: Visibility:hidden property But it still occupies position and replaces its position with a picture.
The advantage is good compatibility
Effect Chart:

Code:

--html--
<div id= "Check" >
<span><input type= "checkbox" class= "Input_check" id= "Check1" > <label for= "Check1" ></label></span>
<span><input type= "checkbox" class= "Input_" Check "id=" Check2 "><label for=" Check2 "></label></span>
</div>
--css--
#check {margin:20px auto;}
#check. Input_check {position:absolute;width:20px;height:20px;visibility:hidden;background: #E92333;}
#check span {position:relative;}
#check. Input_check+label {display:inline-block;width:20px;height:20px;background:url (' settled Application Page 3/Entry Application page/images/ Gou.png ') No-repeat;background-position: -31px-3px;border:1px solid skyblue;
#check. Input_check:checked+label {background-position: -7px-4px;}

2. Use CSS3 to implement
Mainly use after, the disadvantage is that there is a compatibility problem.
Effect

--html--
<div id= "CHECK_CSS3" >
<span><input type= "checkbox" class= "Input_check" id= "Check3" ><label for= "Check3" ></label></span>
<span><input type= "checkbox" class= "Input_" Check "id=" Check4 "><label for=" Check4 "></label></span>
</div>
--css--
 #check_css3 {margin:20px auto;}
  #check_css3 span {position:relative;}
   #check_css3. Input_check {Position:absolute;visibility:hidden}
    #check_css3. Input_check+label {display:inline-block;width:16px;height:16px;border:1px solid #ffd900;} 
    #check_css3. input_check:checked+label:after {content: "";p osition:absolute;left:2px;bottom:12px;width:9px;height : 4px; border:2px solid #e92333; border-top-color:transparent;border-right-color:transparent; -ms-transform:rotate ( -60DEG); -moz-transform:rotate ( -60DEG); -webkit-transform:rotate ( -60DEG); Transform:rotate ( -45deg);}

Here are two ways to implement this, if you have a better and quicker way. Tell me please.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.