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

标签 css

我正在尝试使用纯 CSS 制作自定义复选框,没有必需的标签元素,我知道有很多答案,但我没能按需要制作它。 唯一的问题是当复选框被选中时,我不知道如何添加选中的符号,这是我现在所拥有的

.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">

最佳答案

如果您希望在之后添加复选标记,请将 content 与 html 实体(css 编码)一起使用

.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">

关于css - 创建没有后元素的自定义复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53281304/

相关文章:

ios - 图像中的 Bootstrap Modal 在 iOS 中不起作用

ios - 我的背景在手机和平​​板电脑上看起来不对,怎么办?

css - 如何用JHipster修改CSS样式?

javascript - 改变 HTML 元素的可见性

HTML 文档高度不会拉伸(stretch)到视口(viewport)的全高

html - 文字和图片在同一行

html - Flexbox wkhtmltopdf 渲染问题

css - 是:before :after siblings?

html - 删除布局中的元素会破坏布局

javascript - MS edge 上奇怪的 css 转换动画