纯css实现仿ios的switch开关

效果图如下:
这里写图片描述
这里写图片描述

很简单的HTML结构

<!-- 仿ios的switch开关 -->
    <label for=""><input type="checkbox" name="" id="" class="a-switch"></label>

CSS部分:

主要用到了:
点击label会触发点击所包含的input控件,利用处理label的样式来实现

<style>
        .a-switch{
            width: 60px;
            height: 30px;
            border-radius: 20px;
            -webkit-appearance: none;
            user-select: none;
            outline: none; 
            background-color: #e0e0e0;
            box-shadow: #c2c2c2 0 0 0 0 inset;
            position: relative;
            transition:0.4s;
        }
        .a-switch:before{
            content: '';
            width: 28px;
            height: 28px;
            border-radius: 100%;
            background-color: #fff;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); 
            position: absolute;
            left:0;
            top:1px;
            transition:0.3s;
        }
        .a-switch:checked{
            border-color: #81d480;
            box-shadow: #83e482 0 0 0 14px inset;
            background-color: #81d480; 
        }
        .a-switch:checked:before{
            left:32px;
        }
  </style>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值