html加css制作一个滑动开关

这样的一个开关还是比较常用的,实现的方法也挺多,记录html+css实现的一种

html:

<div class="switch-btn">
	<input type="checkbox" class="hidden-checkbox" name="" value="">
	<span class="switch-area"></span>
	<span class="switch-toggle"></span>
</div>

css:

.switch-btn{
	width: 45px;
	height: 25px;
	position: relative;
	top: 1px;
}
.hidden-checkbox,
.switch-area,
.switch-toggle{
	position: absolute;
	top: 0;
	left: 0;
}
.hidden-checkbox{
	width: 45px;
    height: 25px;
	opacity: 0;
	z-index: 10;
	cursor: pointer;
}
.switch-area{
	width: 100%;
	height: 100%;
	border-radius: 25px;
	background-color: #B3B3B3;
}
.switch-toggle{
	width: 25px;
	    height: 25px;
	border: 1px solid #B3B3B3;
	border-radius: 50%;
	background-color: #fff;
}
//核心代码
.hidden-checkbox:checked ~ .switch-area{
	background-color: #4084F1;
}
.hidden-checkbox:checked ~ .switch-toggle{
	border: 1px solid #4084F1;
	left: 20px;
}
.switch-area,
.switch-toggle{
	-webkit-transition: All 0.3s ease; 
	   -moz-transition: All 0.3s ease; 
	     -o-transition: All 0.3s ease;
	        transition: All 0.3s ease; 
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值