checkbox实现开关按钮

13 篇文章 0 订阅

效果:
关闭时:
在这里插入图片描述
打开时:
在这里插入图片描述
html部分:

 <div class='search_checkbox'>
        <input type='checkbox' id='switch'>
        <label for='switch'></label>
    </div>

css部分

 .search_checkbox {
            margin: 0;
            padding: 0;
            height: 0.62rem;
            width: 1.02rem;
            display: flex;
            box-sizing: border-box;
        }

        .search_checkbox input[type=checkbox] {
            height: 0px;
            width: 0px;
            visibility: hidden;
        }

        .search_checkbox label {
            height: 0.62rem;
            width: 1.02rem;
            cursor: pointer;
            /* height: 20px; */
            border-radius: 0.5rem;
            display: inline-block;
            background-color: #C6CAD3;
            /* width: 40px; */
            text-indent: -99999px;
            position: relative;
        }

        .search_checkbox label::before {
            content: '';
            display: inline-block;
            background-color: #fff;
            height: 0.56rem;
            width: 0.56rem;
            position: absolute;
            top: 0.02rem;
            left: 0.02rem;
            border-radius: 50%;
            transition: 0.3s;
        }

        .search_checkbox input:checked+label {
            background: #2BA0FF;
        }

        .search_checkbox input:checked+label:before {
            left: calc(100% - 0.02rem);
            transform: translateX(-100%);
        }

        .search_checkbox label:active:before {
            width: 0.4rem;
        }

        @media (min-width: 240px) {
            html {
                font-size: 32px;
            }
        }

        @media (min-width: 320px) {
            html {
                font-size: 42.66667px;
            }
        }

        @media (min-width: 360px) {
            html {
                font-size: 48px;
            }
        }

        @media (min-width: 375px) {
            html {
                font-size: 50px;
            }
        }

        @media (min-width: 384px) {
            html {
                font-size: 51.2px;
            }
        }

        @media (min-width: 411px) {
            html {
                font-size: 54.8px;
            }
        }

        @media (min-width: 414px) {
            html {
                font-size: 55.2px;
            }
        }

        @media (min-width: 424px) {
            html {
                font-size: 56.53333px;
            }
        }

        @media (min-width: 480px) {
            html {
                font-size: 64px;
            }
        }
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值