设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 系统 > 正文

纯CSS3代码实现switch滑动开关按钮效果

发布时间:2020-03-16 13:17 所属栏目:52 来源:站长网
导读:副标题#e# XML/HTML Code复制内容到剪贴板 divclass=container divclass=bg_con inputid=checked_1type=checkboxclass=switch/ labelfor=checked_1/label /div /div css代码,:before负责颜色,:after是那个白色小圆点,切换时的过渡效果用css3的动画实现。

XML/HTML Code复制内容到剪贴板

<div class="container">  

        <div class="bg_con">  

            <input id="checked_1" type="checkbox" class="switch" />  

            <label for="checked_1"></label>  

        </div>  

    </div>  

css代码,:before负责颜色,:after是那个白色小圆点,切换时的过渡效果用css3的动画实现。

CSS Code复制内容到剪贴板

.switch{   

        display:none;   

    }   

    label{   

        position:relative;   

        display: block;   

        padding: 1px;   

        border-radius: 24px;   

        height: 22px;   

        margin-bottom: 15px;   

        background-color: #eee;   

        cursor: pointer;   

        vertical-align: top;   

        -webkit-user-select: none;   

    }   

    label:before{   

        content: '';   

        display: block;   

        border-radius: 24px;   

        height: 22px;   

        background-color: white;   

        -webkit-transform: scale(1, 1);   

        -webkit-transition: all 0.3s ease;   

    }   

    label:after{   

        content: '';   

        position: absolute;   

        top: 50%;     

        left: 50%;     

        margin-top: -11px;     

        margin-left: -11px;   

        width: 22px;   

        height: 22px;   

        border-radius: 22px;   

        background-color: white;   

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读