Pure CSS3 for sliding switch effect

Source: Internet
Author: User

The implementation results are as follows:



HTML structure code:
<label class= "Ui-switch" >
<input type= "checkbox" checked= "" >
</label>


CSS code:
/* Form Switch style */
. ui-switch {
Position:absolute;
Font-size:. 16rem;
Right:0.07rem;
top:50%;
Margin-top: -0.16rem;
Width:. 7rem;
Height:. 3rem;
Line-height:. 3rem;
}
. Ui-switch Input {
Width:. 7rem;
Height:. 3rem;
Position:absolute;
top:0;left:0;
Z-index:2;
border:0;
background:0 0;
-webkit-appearance:none;
outline:0
}
. Ui-switch Input:before {
Content: ";
Width:. 68rem;
Height:. 3rem;
border:1px solid #dfdfdf;
Background-color: #fdfdfd;
Border-radius:. 2rem;
Cursor:pointer;
Display:inline-block;
position:relative;
Vertical-align:middle;
-webkit-box-sizing:content-box;
Box-sizing:content-box;
Border-color: #dfdfdf;
-webkit-box-shadow: #dfdfdf 0 0 0 0 inset;
Box-shadow: #dfdfdf 0 0 0 0 inset;
-webkit-transition:border. 4s,-webkit-box-shadow. 4s;
Transition:border. 4s,box-shadow. 4s;
-webkit-background-clip:content-box;
Background-clip:content-box
}

. Ui-switch Input:checked:before {
Border-color: #64bd63;
-webkit-box-shadow: #64bd63 0 0 0 0.16rem inset;
Box-shadow: #64bd63 0 0 0 0.16rem inset;
Background-color: #64bd63;
Transition:border. 4s,box-shadow. 4s,background-color 1.2s;
-webkit-transition:border. 4s,-webkit-box-shadow. 4s,background-color 1.2s;
Background-color: #64bd63
}
. Ui-switch Input:checked:after {
Left:. 4rem
}
. Ui-switch Input:after {
Content: ";
Width:.3rem;
Height:. 3rem;
Position:absolute;
top:50%;
left:0;
-webkit-transform:translatey (-50%);
border-radius:100%;
Background-color: #fff;
-webkit-box-shadow:0 0.01rem 0.03rem Rgba (0,0,0,.4);
box-shadow:0 0.01rem 0.03rem Rgba (0,0,0,.4);
-webkit-transition:left. 2s;
Transition:left. 2s
}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Pure CSS3 for sliding switch effect

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.