css 动画开关按钮

原文链接: http://www.cnblogs.com/xiaobaiv/p/9617520.html
<style>
input[type="checkbox"] {
    display: none;
}
input[type="checkbox"] + label {
    display: inline-block;
    width: 40px;
    height: 20px;
    position: relative;
    -webkit-transition: 0.3s;
    transition: 0.3s;
    margin: 0px 20px;
    box-sizing: border-box;
}
input[type="checkbox"] + label:after {
    content: '';
    display: block;
    position: absolute;
    left: 0px;
    top: 0px;
    width: 20px;
    height: 20px;
    -webkit-transition: 0.3s;
    transition: 0.3s;
    cursor: pointer;
}
#btn:checked + label {
    background: #AEDCAE;
}
#btn:checked + label:after {
    background: #5CB85C;
}
#btn:checked + label:after {
    left: calc(100% - 18px);
}
#btn + label {
    background: #ddd;
    border-radius: 20px;
}
#btn + label:after {
    background: #fff;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    top: 2px;
    left: 2px;
}
</style>
<input type="checkbox" id="btn">
<label for="btn"></label>

转载于:https://www.cnblogs.com/xiaobaiv/p/9617520.html

猜你喜欢

转载自blog.csdn.net/weixin_30399155/article/details/94796928
今日推荐