html - (HTML & CSS) 如何在仍然能够检查图像的同时隐藏复选框

标签 html css checkbox google-chrome-extension

我一直在创建一个具有自定义背景图像的复选框。我想隐藏复选框,但无论何时我都无法选中它。

HTML:

<div class="arrow">
  <label for="togglearrow"></label>
  <input type='checkbox' id="togglearrow"/>
  <div class="arrowmenu"></div>
</div>

CSS:

#togglearrow {
  display: none;
  cursor: pointer;
}

.arrow {
  position: absolute;
  display: block;
  background: url('arrow.png') no-repeat;
  background-size: 65%;
  height: 35px;
  bottom: 0;
}

.arrowmenu {
  position: absolute;
  background: url('test.png') no-repeat;
  background-size: 65%;
  height: 35px;
  bottom: 0;
  right: 20px;
}

label[for="togglearrow"] {
  display: block;
  cursor: pointer;
}

#togglearrow:checked + .arrowmenu {
  display: block;
  bottom: 0;
  left: 50px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

我希望复选框将被隐藏并且仍然可以单击“tasks.png”来选中该框,但是,这会导致无法选中该复选框。

最佳答案

你的 <label>元素没有任何维度。

此外,我不确定是哪个元素 tasks.png是指。

#togglearrow {
  display: none;
}

.arrow {
  position: relative;
  display: block;
  background: url('https://unsplash.it/100') no-repeat;
  background-size: 65%;
  height: 35px;
  bottom: 0;
}

.arrowmenu {
  position: absolute;
  background: url('https://unsplash.it/300') no-repeat;
  background-size: 65%;
  height: 35px;
  bottom: 0;
  right: 20px;
}

label[for="togglearrow"] {
      display: block;
      cursor: pointer;
      width: 40px;
      height: 100%;
      border: 1px solid yellow;
}

#togglearrow:checked + .arrowmenu {
      display: block;
      bottom: 0;
      left: 50px;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
}
<div class="arrow">
  <label for="togglearrow"></label>
  <input type='checkbox' id="togglearrow"/>
  <div class="arrowmenu"></div>
</div>


关于html - (HTML & CSS) 如何在仍然能够检查图像的同时隐藏复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56822393/

相关文章:

javascript - 如何淡化div中背景颜色之间的过渡?

javascript - 单击特定复选框时取消选中除一个复选框之外的所有复选框

带有复选框的 JavaFX ComboBox

javascript - Jquery 时间选择器更改事件的问题

php - 我如何让 emacs 区分我在编写 PHP、HTML 和 JavaScript 时的区别?

javascript - 单击表单登录时防止子菜单隐藏/单击父 li 时更改背景颜色

jquery - 如何使用 jquery ajax 将选中复选框的值发送到另一个页面

css - 网站标题问题

html - 如何让单边框阴影从边到边出现?

html - 如何将父元素的宽度折叠为子元素的总宽度