【发布时间】:2021-03-13 14:10:05
【问题描述】:
我是新手,我尝试了解复选框的工作原理,我尝试制作一个选中时为彩色的 Heart 复选框,并且我用选中的心覆盖空心,但它不起作用...
似乎输入没有作用于标签...
提前谢谢你
我将代码放在 Codepen 上: https://codepen.io/steven-fabre/pen/KKNJdBP
input[type="checkbox"]{
display: none;
}
.heart_checked {
opacity: 0;
z-index: 999;
}
.heart_checked {
font-weight: bold;
background: -webkit-linear-gradient(#9356dc, #FF79DA);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
label{
position: absolute;
top: 24px;
right: 24px;
font-size: 25px;
}
.fa-heart,input{
cursor: pointer;
position: absolute;
right: 24px;
}
label > input[type="checkbox"]:checked + .heart_checked {
opacity: 1;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.2/css/all.css" integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu" crossorigin="anonymous">
<label>
<input type="checkbox">
<i class="far fa-heart"></i>
<i class="fas fa-heart heart_checked"></i>
</label>
【问题讨论】: