You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用CSS移除复选框的边框与背景色?

如何用CSS移除复选框的边框及背景颜色

要移除复选框的边框和背景颜色,需先清除浏览器自带的默认样式,再设置自定义样式,具体实现如下:

CSS 代码

label input[id="cb1"] {
  width: 14px;
  height: 14px;
  /* 清除浏览器默认外观,核心步骤 */
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 0;
  cursor: pointer;
  /* 移除背景颜色 */
  background-color: transparent;
}

/* 可选:自定义选中状态的勾选标记 */
label input[id="cb1"]:checked:after {
  content: "✓";
  display: block;
  text-align: center;
  line-height: 14px;
}

HTML 代码

<label for="cb1"><input type="checkbox" id="cb1"></label>

关键说明

  • appearance: none 及 -webkit-appearance: none 用于清除浏览器自带的复选框默认样式,只有这样,后续的边框、背景色设置才能生效。
  • border: none 直接移除复选框边框,background-color: transparent 确保背景完全透明。
  • 选中状态的伪元素样式可根据需求调整或删除,若不需要自定义勾选标记,仅保留前半部分CSS即可。

内容的提问来源于stack exchange,提问作者EMahan K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 06:30:04