css 美化checkbox复选框

这里写图片描述

sass

.icon-checked:before {
    content: "\e83b";
}
.com-checkbox {
    position: relative;
    display: inline-block;
    width: 22px;
    height: 20px;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 3px;
    text-align: center;
    vertical-align: middle;
    &:hover {
        border-color: #b7b7b7;
    }
    input,
    input + i {
        position: absolute;
        z-index: 1;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        margin: auto;
    }
    input {
        z-index: 2;
        opacity: 0;
        cursor: pointer;
        & + .iconfont {
            display: none;
            line-height: 18px;
            font-weight: bold;
            color: #999;
        }
        &:checked + .iconfont {
            display: block;
        }
    }
}

html

<span class="com-checkbox">
  <input type="checkbox" name="">
  <i class="iconfont icon-checked"></i>
</span>

其它方法

  • 使用 label 嵌套 checkbox、span(或者 i 都行)
  • checkbox 设置隐藏
  • :checked + span 实现效果

猜你喜欢

转载自blog.csdn.net/pintu274111451/article/details/79936757