Using CSS to implement a switches switch button for imitation iOS7

Source: Internet
Author: User
Tags switches
This article mainly introduces a pure CSS implementation of an imitation ios7 switches switch button, without the introduction of JS code. In the implementation of the two colors, three different sizes of the demo, the need for friends can refer to the next

Today we introduce an imitation ios7 switches switch button. This button is also a pure CSS implementation. No need to draw JS code. In the implementation of the two colors, three different sizes of the demo. Look together:

The implemented code.

  HTML code:

<p class= "wrap" style= "width:600px; Margin:auto; " > 

CSS code:

Input[type= "checkbox"] {position:absolute;        opacity:0;            }/* Normal track */input[type= "checkbox"].ios-switch + p {vertical-align:middle;            width:40px;            height:20px;            border:1px solid Rgba (0,0,0,.4);            border-radius:999px;            Background-color:rgba (0, 0, 0, 0.1);            -webkit-transition-duration:. 4s;            -webkit-transition-property:background-color, Box-shadow;            Box-shadow:inset 0 0 0 0px rgba (0,0,0,0.4);        margin:15px 1.2em 15px 2.5em;            }/* Checked track (Blue) */input[type= "checkbox"].ios-switch:checked + p {width:40px;            background-position:0 0;            Background-color: #3b89ec;            border:1px solid #0e62cd;        Box-shadow:inset 0 0 0 10px rgba (59,137,259,1);  }/* Tiny track */input[type= "checkbox"].tinyswitch.ios-switch + p {          width:34px;        height:18px;            }/* Big track */input[type= "checkbox"].bigswitch.ios-switch + p {width:50px;        height:25px; }/* Green track */input[type= "checkbox"].green.ios-switch:checked + P {background-color            : #00e359;            border:1px solid Rgba (0, 162, 63,1);        Box-shadow:inset 0 0 0 10px rgba (0,227,89,1);            }/* Normal knob */input[type= "checkbox"].ios-switch + p > P {float:left;            width:18px;            height:18px;            Border-radius:inherit;            Background: #ffffff;            -webkit-transition-timing-function:cubic-bezier (. 54,1.85,.5,1);            -webkit-transition-duration:0.4s;            -webkit-transition-property:transform, Background-color, Box-shadow;            -moz-transition-timing-function:cubic-bezier (. 54,1.85,.5,1);       -moz-transition-duration:0.4s;     -moz-transition-property:transform, Background-color;            box-shadow:0px 2px 5px rgba (0, 0, 0, 0.3), 0px 0px 0 1px rgba (0, 0, 0, 0.4);            Pointer-events:none;            margin-top:1px;        margin-left:1px; }/* Checked knob (Blue Style) */input[type= "checkbox"].ios-switch:checked + p > P {-            Webkit-transform:translate3d (20px, 0, 0);            -moz-transform:translate3d (20px, 0, 0);            Background-color: #ffffff;        box-shadow:0px 2px 5px rgba (0, 0, 0, 0.3), 0px 0px 0 1px rgba (8, 80, 172,1);            }/* Tiny knob */input[type= "checkbox"].tinyswitch.ios-switch + p > P {width:16px;            height:16px;        margin-top:1px;        }/* Checked Tiny Knob (Blue Style) */input[type= "checkbox"].tinyswitch.ios-switch:checked + P > P            {-webkit-transform:translate3d (16px, 0, 0); -moz-transform:translate3d (16PX, 0, 0);        box-shadow:0px 2px 5px rgba (0, 0, 0, 0.3), 0px 0px 0 1px rgba (8, 80, 172,1);            }/* Big knob */input[type= "checkbox"].bigswitch.ios-switch + p > P {width:23px;            height:23px;        margin-top:1px;        }/* Checked Big Knob (Blue Style) */input[type= "checkbox"].bigswitch.ios-switch:checked + P > P            {-webkit-transform:translate3d (25px, 0, 0);            -moz-transform:translate3d (16px, 0, 0);        box-shadow:0px 4px 8px rgba (0, 0, 0, 0.3), 0px 0px 0 1px rgba (8, 80, 172,1); }/* Green knob */input[type= "checkbox"].green.ios-switch:checked + p > P {Box-shadow        : 0px 2px 5px rgba (0, 0, 0, 0.3), 0 0 0 1px rgba (0, 162, 63,1);            }/* Needless Page decoration */body {-webkit-user-select:none;            Cursor:default;            font:18px "Helvetica Neue"; Color:rgba (0, 0, 0, 0.77);            font-weight:200;            padding-left:30px;            padding-top:0px;            Background:-webkit-linear-gradient (top, #f2fbff 0, #ffffff 64%) no-repeat;            Background:-moz-linear-gradient (top, #f2fbff 0, #ffffff 64%) no-repeat;            Background:-ms-linear-gradient (top, #f2fbff 0, #ffffff 64%) no-repeat;        Background:linear-gradient (to bottom, #f2fbff 0, #ffffff 64%) no-repeat;            } h1 {font-weight:100;            font-size:40px;        Color: #135ae4;            } h2 {font-weight:200;            font-size:22px;        Color: #03b000;            } h3 {font-weight:200;            font-size:18px;            Color:rgba (0, 0, 0, 0.77);        margin-top:50px;            } a:link {text-decoration:none;        Color: #f06;            } a:visited {text-decoration:none; Color: #f06;        } a:hover {text-decoration:underline;        } a:active {text-decoration:underline;   }

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.