创建没有后置元素的自定义复选框

时间:2018-11-13 12:45:00

标签: css css3

我正在尝试使用纯CSS创建自定义复选框,而没有必需的label元素,我知道有很多答案,但是我没有设法做到这一点。 唯一的问题是,当我选中复选框时,我不知道如何添加选中的标志,这是我现在拥有的

.checkbox-custom {
  &:after {
    line-height: 1.5em;
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    margin-top: -4px;
    margin-left: -4px;
    border: 1px solid grey;
    border-radius: 0;
    background-color: white;
  }
  &:checked:after {
    width: 15px;
    height: 15px;
    color: grey;
  }
}
<input type="checkbox" class="checkbox-custom">

1 个答案:

答案 0 :(得分:1)

如果您希望在其后添加对勾标记,请对HTML实体(采用CSS编码)使用content

.checkbox-custom::after {
  line-height: 1.5em;
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-top: -4px;
  margin-left: -4px;
  border: 1px solid grey;
  border-radius: 0;
  background-color: white;
}

.checkbox-custom:checked::after {
  content:'\2713';
  font-size: 20px;
  line-height: 1em;
  width: 18px;
  height: 18px;
  color: grey;
  text-align:center;
}
<input type="checkbox" class="checkbox-custom">

相关问题