CSS custom checkbox and Radio styles

Source: Internet
Author: User

Very common problem, there are many people have written similar articles, write their own to record

The CSS code is as follows:
#myCheck + label,.myradio + label{width:16px;Height:16px;Border:1px solid #09c;Display:Inline-block;text-align:Center;vertical-align:Middle;Line-height:15px;font-size:12px;}#myCheck + Label{Border-radius:3px;}. MyRadio + Label{Border-radius:50%;}#myCheck: Checked + label:after,.myradio:checked + label:after{Color:#09c;}#myCheck: Checked + label:after{content:"?";}. myradio:checked + label:after{content:"";}
The DOM structure is as follows:
<inputtype= "checkbox"ID= "MyCheck"><label for= "MyCheck"></label><inputtype= "Radio"class= "MyRadio"ID= "MyRadio1"name= "Test"><label for= "MyRadio1"></label><inputtype= "Radio"class= "MyRadio"ID= "MyRadio2"name= "Test"><label for= "MyRadio2"></label>
The effect is as follows:

It is important to note that:

1. Label needs to be written after input , because the label style is set according to input

2. Do not use display:none when hiding ijnput, as this will remove it completely from the tab switch Focus queue, you can set the width height to 0, or move out of the page display area, or set the opacity:0 Or use a crop, whatever you think is the right way to do it.

This article simply wrote down the implementation of ideas and methods, the project label can set the background picture, even because the framework is popular, many people prefer not to use Ckeckbox or radio , but instead of other elements, Use state to control the style of an element

If there is inaccurate expression, welcome to correct, welcome to add, thank you for reading.

CSS custom checkbox and Radio styles

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.