CSS implementation of the mobile phone switch (switch plug-in)

Source: Internet
Author: User

On many designs, like switches or radio, today I'll talk about how to use CSS to implement dynamic switches.

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201710/20/6ef1c4dc7cf6cefc2ab0bf8038c40092.jpg-wh_500x0-wm_3 -wmp_4-s_2865585867.jpg "title=" 2017-10-20_163712.jpg "alt=" 6ef1c4dc7cf6cefc2ab0bf8038c40092.jpg-wh_ "/>

In the HTML code, it's very simple.

<input type= "checkbox" id= "1" class= "checkbox" ><label class= "switch" for= "1" ></label>


Below is our CSS code

<style>    .checkbox {        display:  none;    }    .switch {         width: 50px;        height: 31px;         background:  #56ACFE;         border-radius: 20px;        padding: 1px;         box-sizing: border-box;         display: inline-block;        margin-top: 15px;     }    .switch:after {         content:  ';         box-shadow: 0 3px 8px 0  rgba (0,0,0,0.15),   0 1px 1px 0 rgba (0,0,0,0.16),  0 3px 1px 0 rgba (0,0,0,0.10);         width: 28px;         height: 28px;        background:  #fff;         border-radius: 50%;         display: block;        margin-left: 1px;         float: left;        transition:  all 0.5s;    }    .checkbox:checked+.switch:after {         margin-left: 20px;    }     .checkbox:checked+.switch {        background: # ccc;    }</sTyle> 

In this way, the switch that often appears on the design and on the phone is realized.


If you can help, trouble to praise, if there are comments or suggestions, private messages I oh!

I will continue to work hard to accumulate experience, will give you do not regularly share the basic knowledge points of *-*, pay attention to me Oh!


This article from the "front-end Development" blog, reproduced please contact the author!

CSS implementation of the mobile phone switch (switch plug-in)

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.