css - 如何将复选框的背景颜色更改为黑色?
问题描述
目前我遇到了一个项目,需要将输入框的背景颜色改为黑色。我在网上搜索了一些资料,但仍然无法成功更改颜色。你愿意帮我找出问题所在吗?
input[type=checkbox] {
background-color: #222;
padding: 3px 6px;
border: 1px solid red;
color: #fff;
user-select: none; /* 防止文字被滑鼠選取反白 */
}
input[type=checkbox]:checked:after {
display: inline-block;
content:"";
color: #fff;
background-color:#222;
}
/* input[type=checkbox]:checked:after {
content: "X";
background-color: #FFFFFF;
font-size: 12px;
text-align:center;
} */
<input type="checkbox"><label for="enter-send" class="enter-send"> Enter </label>
解决方案
您必须编写自定义 CSS 来设置复选框的样式。
/* This css is for normalizing styles. You can skip this. */
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.new {
padding: 50px;
}
.form-group {
display: block;
margin-bottom: 15px;
}
.form-group input {
padding: 0;
height: initial;
width: initial;
margin-bottom: 0;
display: none;
cursor: pointer;
}
.form-group label {
position: relative;
cursor: pointer;
}
.form-group label:before {
content:'';
-webkit-appearance: none;
background-color: transparent;
border: 2px solid black;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
padding: 10px;
display: inline-block;
position: relative;
vertical-align: middle;
cursor: pointer;
margin-right: 5px;
}
.form-group input:checked + label:before {
background: black;
}
.form-group input:checked + label:after {
content: '';
display: block;
position: absolute;
top: 2px;
left: 9px;
width: 6px;
height: 14px;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
<div class="new">
<form>
<div class="form-group">
<input type="checkbox" id="html">
<label for="html">HTML</label>
</div>
<div class="form-group">
<input type="checkbox" id="css">
<label for="css">CSS</label>
</div>
<div class="form-group">
<input type="checkbox" id="javascript">
<label for="javascript">Javascript</label>
</div>
</form>
</div>
推荐阅读
- powershell - 【PowerShell】 有没有完美的方法不将错误写入$Error?
- java - 云网关无法通过网关访问服务但直接访问没有问题
- python - 以特定方式从 xlsx 文件打印数据帧
- r - 为采样天数创建一个列,例如 0、10、30 天,从每个研究区域的 0 天开始?
- css - 滚动快照不适用于 chrome,但适用于 Firefox
- python - 我不得不做一个天气预报项目。无法在 jupyter 中导入数据集
- java - 如何从另一个活动设置活动的内容视图
- vue.js - 从 vue devServer 中的自定义本地域中删除端口
- ruby-on-rails - Webpacker 设置中未定义 Rails UJS
- python - 我正在尝试训练我的 X_train 和 y_train 但存在一些数组维度问题