【发布时间】:2023-04-03 20:05:02
【问题描述】:
我在 codepen 上发现了一个看起来非常干净的自定义复选框,并且刚刚更新了一个项目来使用它。现在我为表单的不同部分设置了不同的背景颜色,但我只想将背景设置为图标而不是纯色
注释掉的东西不起作用
.label-switch {
display: inline-block;
position: relative;
}
.label-switch::before,
.label-switch::after {
content: "";
display: inline-block;
cursor: pointer;
transition: all 0.5s;
}
.label-switch::before {
width: 3em;
height: 1em;
border: 1px solid #757575;
border-radius: 4em;
background: #888888;
}
.label-switch::after {
position: absolute;
left: 0;
top: -20%;
width: 1.5em;
height: 1.5em;
border: 1px solid #757575;
border-radius: 4em;
background: #ffffff;
}
.input-switch:checked~.label-switch::before {
background: #00a900;
border-color: #008e00;
}
.input-switch:checked~.label-switch::after {
left: unset;
right: 0;
background: #00ce00;
/*background-image:(url(http://pngimg.com/uploads/pokeball/pokeball_PNG8.png);*/
/*background: url(http://pngimg.com/uploads/pokeball/pokeball_PNG8.png);*/
border-color: #009a00;
}
<input class='input-switch' type="checkbox" id="demo" />
<label class="label-switch" for="demo"></label>
<span class="info-text"></span>
【问题讨论】:
-
不确定我的理解是否正确,但这是您要找的吗? (黄色是小占位符图片) -- codepen.io/JimmyJames88/pen/WVJzgq
-
基本上是的。另一个回答的家伙有我正在谈论的图像。谢谢回复