checkbox样式自定义

原理: 隐藏 input 默认的样式 通过label for input 去映射 checkbox 选中和未选中状态的转换;

上代码:

//  html
<input type="checkbox" id="checkbox-1-1" class="regular-checkbox"  v-model="checkStatus" @click="toggle"/>
<label for="checkbox-1-1" class="my-check-label"></label>
//  css
   input[type="checkbox"] {
        opacity: 0;// 隐藏默认样式
        z-index: 2;
     }
      label{
    color: #999;
    font-size: 16px;
    width: 13px;
    height: 13px;
    border: 1px solid #ccc;
    font-weight: normal;
    position: absolute;
    pointer-events: none;
    left: 0px;
    top: 1.5px;
    transition: 0.2s ease all;
    -moz-transition: 0.2s ease all;
    -webkit-transition: 0.2s ease all;
      }
      label.chbox_label:before {
          content: '';
          position: absolute;
          top: 1px;
          left: -22px;
          width: 13px;
          height: 13px;
          border: 1px solid #ccc;
          border-radius: 2px ;
      }
input[type="checkbox"]:checked+label:after {
    content:  "";
    position: absolute;
    top: -1px;
    left: -1px;
    width: 13px;
    height: 13px;
    background: url("../../assets/select.png") no-repeat;
    background-size: cover;
    // background-position-x: -2.2px;
    // background-position-y: -2px;
    border: 1px solid #ccc;
    border-radius: 2px;
}

另外:
浏览器 在选择记住密码是会为input 输入框添加一个背景色;去掉背景色代码为:

input:-webkit-autofill , textarea:-webkit-autofill, select:-webkit-autofill 
     transition: background-color 50000s ease-in-out 0s;
      //背景色透明  生效时长  过渡效果  启用时延迟的时间(时间可以尽量设置长一些)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值