純css實現 switch開關


<!-- 直接看代碼,利用了css3兄弟選擇器 -->
<!-- html -->

<
button class="switch"> <input type="checkbox"> <span><i></i></span> </button>
/*scss*/

.switch
{ position: relative; width: 50px; height: 25px; background-color: #fff; border: none; outline: none; i { position: absolute; left: 0; top: 0; display: block; height: 23px; width:23px; border-radius: 50%; border: 1px solid #dadada; background-color: #fff; transition: all .2s; } span{ position: absolute; display: block; top: 0; left: 0; right: 0; bottom: 0; border: 1px solid #dadada; border-radius: 25px; z-index: 0; } input{ position: absolute; top: 0; left: 0; width: 50px; height: 25px; margin: 0; padding: 0; opacity: 0; z-index: 9999; &:checked + span{ background-color: #58ad2c; border-color: #58ad2c; } &:checked + span i{ background-color: #fff; border-color: #58ad2c; left: 25px; } } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM