css實現手機中開關(開關外掛程式)

來源:互聯網
上載者:User

標籤:css   開關   單選   

在很多設計圖上,會有如開關或者單選,今天我就來講講如何用css去實現動態開關。

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_" />

html代碼中,是很簡單的

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


下面是我們css代碼

<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>

就這樣,就實現了這個設計圖上和手機上經常出現的開關。


如果對你能有協助的話,麻煩點贊,如果有意見或者建議的話,私信我哦!

我會繼續努力積攢經驗的,會給大家不定時分享基礎知識點的*-*,關注我哦!


本文出自 “前端開發” 部落格,轉載請與作者聯絡!

css實現手機中開關(開關外掛程式)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.