Css3 changes the single-choice and multi-choice input styles, and css3input multiple-choice

Source: Internet
Author: User

Css3 changes the single-choice and multi-choice input styles, and css3input multiple-choice

During project development, we often encounter the need to change the input Single-choice and multi-choice styles. Today we will introduce a simple method to change the input Single-choice and multi-choice styles.

Before that, let's briefly introduce the before pseudo class.

: The before selector inserts content before the selected element. Use the content attribute to specify the content to be inserted (content is required ).

I believe this is not hard to understand. Next we will first understand the concept:

(1) first define the tag for the input element with label in html, that is, when you click the label, the corresponding input will also be selected or canceled.

(2) The next step is to write css and hide the input. You only need to add your style before the label. It can be an image or a circle drawn by yourself, the following example shows the circle I wrote. Of course, it can be replaced with a background image.

Input [type = "radio"] + label: before is an unselected style.
Input [type = "radio"]: checked + label: before is the selected style.
<Input type = "radio" id = "nationality1"> <label for = "nationality1"> China </label> </div>
input[type="radio"]{    display:none;}input[type="radio"]+label{    position: relative;}input[type="radio"]+label:before{    content: "";    width:25px;    height:25px;    background: #ffffff;    border:2px solid $gray;    position: absolute;    bottom:3px;    left: -35px;    border-radius: 50%;}                                                   
input[type="radio"]:checked+label:before{ content: ""; width: 25px; height: 25px; background: #34c0f5; position: absolute; bottom:3px; left: -35px; z-index: 99; border-radius: 50%;}

Replace radio with checkbox.

Note: hidden and pseudo-class positioning are the key

Related Article

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.