{"id":23620,"date":"2015-07-24T22:46:22","date_gmt":"2015-07-24T17:16:22","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=23620"},"modified":"2015-07-24T22:46:22","modified_gmt":"2015-07-24T17:16:22","slug":"build-custom-ios-swipe-button-with-css3","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/build-custom-ios-swipe-button-with-css3\/","title":{"rendered":"Build Custom iOS Swipe Button with CSS3"},"content":{"rendered":"<p>There are many ways to make iOS swipe button with toggle effect:<\/p>\n<p>But CSS and CSS3 is the best way to make these buttons because of its light weight.<\/p>\n<h3>Here is the image of what we are going to make:<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/07\/switch-btn.jpg\" alt=\"switch-btn\" width=\"158\" height=\"45\" class=\"alignnone size-full wp-image-23633\" \/><\/p>\n<h3>Let\u2019s start with the HTML code <\/h3>\n<p>In this I have used checkbox to use the functionality of click. But we will not display these input checkboxes. We can use display none to hide the checkbox.<\/p>\n<h3>\n&nbsp;<br \/>\nHTML Code <\/h3>\n<p>[java]<br \/>\n&lt;div class=&quot;swipe-btn&quot;&gt;<br \/>\n    &lt;input type=&quot;checkbox&quot; id=&quot;checkbox3&quot;&gt;<br \/>\n    &lt;label for=&quot;checkbox3&quot;&gt;&lt;b&gt;&lt;\/b&gt;&lt;\/label&gt;<br \/>\n&lt;\/div&gt;<br \/>\n[\/java]<\/p>\n<p>&nbsp; <br \/>\n<b>CSS Code:<\/b> use below css code one by one<br \/>\n&nbsp;<\/p>\n<p>Styling of swipe-btn div:<\/p>\n<p>[java]<br \/>\n.swipe-btn {<br \/>\n    display: inline-block;<br \/>\n    width: 70px;<br \/>\n    height: 36px;<br \/>\n    position: relative;<br \/>\n    border-radius: 20px;<br \/>\n    color: #FFF;<br \/>\n    overflow: hidden;<br \/>\n    box-shadow: 0 1px 0 #CCC;<br \/>\n    border: 1px solid #D3D2D2;<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Styling of label:<\/p>\n<p>[java]<br \/>\n.swipe-btn label {<br \/>\n    width: 200%;<br \/>\n    height: 36px;<br \/>\n    line-height: 30px;<br \/>\n    position: absolute;<br \/>\n    top: 0;<br \/>\n    left: 0;<br \/>\n    -webkit-transition: 0.13s;<br \/>\n    -moz-transition: 0.13s;<br \/>\n    transition: 0.13s;<br \/>\n    font-size: 12px;<br \/>\n    z-index: 1;<br \/>\n    cursor: pointer;<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Use of ::after, ::before pseudo element<\/p>\n<p>[java]<\/p>\n<p>.swipe-btn label::before {<br \/>\n    content: &quot;ON&quot;;<br \/>\n    width: 50px;<br \/>\n    height: 36px;<br \/>\n    float: left;<br \/>\n    margin-right:-20px;<br \/>\n    padding: 3px 0 0 4px;<br \/>\n    text-align: center;<br \/>\n    background: #007FEA;<br \/>\n    text-indent: -16px;<br \/>\n}<\/p>\n<p>.swipe-btn label::after {<br \/>\n    content: &quot;OFF&quot;;<br \/>\n    width: 50px;<br \/>\n    height: 36px;<br \/>\n    float: left;<br \/>\n    margin-left:-15px;<br \/>\n    padding: 3px 0 0 4px;<br \/>\n    text-align: center;<br \/>\n    color: #999;<br \/>\n    background: #ccc;<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Then we give styling to b(bold) tag which will move in label tag on click of checkbox:<\/p>\n<p>[html]<\/p>\n<p>.swipe-btn label b {<br \/>\n    display: block;<br \/>\n    width: 36px;<br \/>\n    height: 36px;<br \/>\n    float: left;<br \/>\n    position: relative;<br \/>\n    z-index: 1;<br \/>\n    border: 1px solid #D3D2D2;<br \/>\n    background: #fff;<br \/>\n    border-radius: 20px;<br \/>\n}<br \/>\n[\/html]<\/p>\n<p>Then we hide the checkbox:<\/p>\n<p>[java]<br \/>\n.swipe-btn input {display: none;}<br \/>\n[\/java]<\/p>\n<p>\n<br \/>When we click on checkbox b(bold) tag will move left in label tag. And we use pseudo-class selector \u201c:checked\u201d for moving b(bold) tag. <\/p>\n<p><b>Note: We can replace \u201c:checked\u201d with a class also. <\/b><br \/>\n[java]<br \/>\n.swipe-btn input:checked ~ label {<br \/>\n    left:-35px;<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>\n<br \/><b>Note:<\/b> If you want to customise these buttons. You can use font Awesome in place of content: \u201cON\u201d and content: \u201cOFF\u201d in css. Or you can use background image in place of content.<\/p>\n<p>I hope you enjoyed and hope you&#8217;re taking what you see here and expand or improve upon it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many ways to make iOS swipe button with toggle effect: But CSS and CSS3 is the best way to make these buttons because of its light weight. Here is the image of what we are going to make: Let\u2019s start with the HTML code In this I have used checkbox to use the [&hellip;]<\/p>\n","protected":false},"author":231,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":36},"categories":[1],"tags":[355,4842],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23620"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/231"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=23620"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23620\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=23620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=23620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=23620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}