css 写一个滑块按钮

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <!-- 

        name="viewport"兼容移动端

        initial-scale= 1.0  表示 pc 移动端 = 1:1

     -->

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

    <!-- <link rel="stylesheet" href="../dzmQueryUI/dzmQuerySwitch.css"> -->

    <style>

/* 必须是input 为  checkbox  class 添加  switch  才能实现以下效果 */

input[type="checkbox"].switch {

  appearance: none;

  outline: none;

  -webkit-appearance: none;

  -moz-appearance: none;

  position: relative;

  width: 2.8rem;

  height: 1.52rem;

  border: 1px solid #ccc;

  background-color: #ccc;

  border-radius: 0.7rem;

}

.switch::after {

  content: "";

  display: inline-block;

  width: 1.4rem;

  height: 1.4rem;

  border-radius: 50%;

  background-color: #fff;

  box-shadow: 0 0 2px #999;

  transition: left 0.2s;

  top: 0;

  left: 0;

  position: absolute;

}

input[type="checkbox"].switch:checked {

  background-color: #45b97c;

}

/* 

    默认不被选中

      当input[type="checkbox"] 被选中的时候 伪元素显示下面样式  定位发生变化

     */

input[type="checkbox"].switch:checked::after {

  top: 0;

  left: 1.42rem;

  position: absolute;

}

 

/* 状态 */

 

input[type="checkbox"]:checked.switch.switch-info {

    background-color: #33a3dc;

}

input[type="checkbox"]:checked.switch.switch-danger {

    background-color: rgb(255, 73, 73);

}

input[type="checkbox"]:checked.switch.switch-primary {

background-color: #009ad6;

}

input[type="checkbox"].switch.switch-primary{

    background-color: rgb(255, 73, 73);

}

input[type="checkbox"]:checked.switch.switch-warm {

    background-color:#f47920;

}


 

    </style>

</head>

<body>

    <input type="checkbox" class="switch">

    <input type="checkbox" class="switch switch-danger">

    <input type="checkbox" class="switch switch-info">

    <input type="checkbox" class="switch switch-primary">

    <input type="checkbox" class="switch switch-warm">

   

</body>

</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值