溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么用css實(shí)現(xiàn)switches開關(guān)按鈕

發(fā)布時(shí)間:2021-08-10 20:43:15 來(lái)源:億速云 閱讀:138 作者:chen 欄目:web開發(fā)

本篇內(nèi)容主要講解“怎么用css實(shí)現(xiàn)switches開關(guān)按鈕”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么用css實(shí)現(xiàn)switches開關(guān)按鈕”吧!

  今天給大家介紹一款仿ios7的switches開關(guān)按鈕。這款按鈕也是純css實(shí)現(xiàn)的。無(wú)需引js代碼。在實(shí)現(xiàn)中給出了兩種顏色,三種不同大小的demo。一起看下效果圖:

怎么用css實(shí)現(xiàn)switches開關(guān)按鈕

  實(shí)現(xiàn)的代碼。

  html代碼:

代碼如下:

<div class="wrap" >
       <h2>
           iOS 7 style switches with CSS</h2>
       <h3>
           By Bandar Raffah</h3>
       <label>
           Big<input type="checkbox" class="ios-switch green  bigswitch" checked /><div>
               <div>
               </div>
           </div>
       </label>
       <label>
           <input type="checkbox" class="ios-switch bigswitch" checked /><div>
               <div>
               </div>
           </div>
       </label>
       <label>
           Normal<input type="checkbox" class="ios-switch green" /><div>
               <div>
               </div>
           </div>
       </label>
       <label>
           <input type="checkbox" class="ios-switch" /><div>
               <div>
               </div>
           </div>
       </label>
       <label>
           Tiny<input type="checkbox" class="ios-switch green tinyswitch" checked /><div>
               <div>
               </div>
           </div>
       </label>
       <label>
           <input type="checkbox" class="ios-switch tinyswitch" checked /><div>
               <div>
               </div>
           </div>
       </label>
 </div>

  css代碼:

代碼如下:

input[type="checkbox"]
       {
           position: absolute;
           opacity: 0;
       }
       
       /* Normal Track */
       input[type="checkbox"].ios-switch + div
       {
           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 + div
       {
           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 + div
       {
           width: 34px;
           height: 18px;
       }
       
       /* Big Track */
       input[type="checkbox"].bigswitch.ios-switch + div
       {
           width: 50px;
           height: 25px;
       }
       
       /* Green Track */
       input[type="checkbox"].green.ios-switch:checked + div
       {
           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 + div > div
       {
           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 + div > div
       {
           -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 + div > div
       {
           width: 16px;
           height: 16px;
           margin-top: 1px;
       }
       
       /* Checked Tiny Knob (Blue Style) */
       input[type="checkbox"].tinyswitch.ios-switch:checked + div > div
       {
           -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 + div > div
       {
           width: 23px;
           height: 23px;
           margin-top: 1px;
       }
       
       /* Checked Big Knob (Blue Style) */
       input[type="checkbox"].bigswitch.ios-switch:checked + div > div
       {
           -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 + div > div
       {
           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;
       }
       h2
       {
           font-weight: 100;
           font-size: 40px;
           color: #135ae4;
       }
       h3
       {
           font-weight: 200;
           font-size: 22px;
           color: #03b000;
       }
       h4
       {
           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;
       }  

到此,相信大家對(duì)“怎么用css實(shí)現(xiàn)switches開關(guān)按鈕”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI