小编Pet*_*ter的帖子

用图标替换复选框元素

我想自定义浏览器复选框。当状态被选中时,应该显示 图标,checked.svg而不是复选框和图标unchecked.svg

这是我的代码。HTML:

<div class="checkbox-custom">
   <input type="checkbox"/>
      <div class="checkmark">
          <img src="@/assets/images/icons/checkbox/unchecked.svg" class="unchecked"/>
          <img src="@/assets/images/icons/checkbox/checked.svg" class="checked"/>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

SAS:

.checkbox-custom {
    position: absolute;
    width: 28px;
    height: 28px;
    left: 0;
    top: 0;

    // Hide default browser checkbox
    input[type=checkbox] {
                display: none;
            }

   input[type=checkbox] + .checkmark {
        position: absolute;
        left: 3.5px;
        top: 3.5px;
        right: 3.5px;
        bottom: 3.5px;

        display: inline-block;
        cursor: pointer;

        img {
            width: 21px;
            height: 21px;
        }

        .checked {
            display: none;
        }
    }    

    input[type=checkbox]:checked + .checkmark {
        .checked …
Run Code Online (Sandbox Code Playgroud)

html css checkbox sass

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

checkbox ×1

css ×1

html ×1

sass ×1