html 滑块按钮,纯css的滑块开关按钮

之前在项目中使用滑块开关按钮,纯css写的,不考虑兼容低版本浏览器,先说下原理:

使用 checkbox 的 选中 checked 属性改变css 伪类样式, 一定要使用-webkit-appearance: none; 先清除checkbox的默认样式 ,否则写其他的样式不起作用;

好,不多说,直接上代码:

css滑块开关

.checke{

position: relative;

-webkit-appearance: none;

width:90px;

height: 44px;

line-height: 44px;

background: #eee;

border-radius: 30px;

outline: none;

}

.checke:before{

position: absolute;

left: 0;

content: '';

width: 44px;

height: 44px;

border-radius: 50%;

background: #eee;

box-shadow: 0px 0px 5px #ddd;

transition: all 0.2s linear;

}

.checke:checked{

background: #18ff0a;

}

.checke:checked:before{

left: 45px;

transition: all 0.2s linear;

}

一个干净整洁的按钮代码就产生了!如果需要根据按钮样式,决定某个数据值,就要写在js中判断 checkbox 是否选择就ok了,简单易用!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值