【发布时间】:2015-09-04 10:17:16
【问题描述】:
我正在开发一个带有收音机的 CSS 星级评级系统。 但是我似乎无法弄清楚我在这里做错了什么......当我点击时它似乎突出显示......但当我悬停时它应该突出显示。
<fieldset>
<input type="radio" id="star-5" name="rating-01" value="5"><label for="star-5"></label>
<input type="radio" id="star-4" name="rating-01" value="4"><label for="star-4"></label>
<input type="radio" id="star-3" name="rating-01" value="3"><label for="star-3"></label>
<input type="radio" id="star-2" name="rating-01" value="2"><label for="star-2"></label>
<input type="radio" id="star-1" name="rating-01" value="1"><label for="star-1"></label>
</fieldset>
input[type=radio] { display: none; visibility: collapse; }
input[type=radio] + label {
position: relative; float: right; clear: none; display: block;
width: 18.4%; height: 120px; margin: 0 1% 0 1%; padding: 0;
outline: 0; cursor: pointer;
background-color: green;
}
input[type=radio]#star-1 + label { margin: 0 1% 0 0; } input[type=radio]#star-5 + label { margin: 0 0 0 1%; }
input[type=radio]:hover + label,
input[type=radio]:hover + label ~ input[type=radio] + label {
background-color: red;
}
更新
这就是我到目前为止所做的事情:JSFiddle;
CSS:
input[type=radio] { display: none; visibility: collapse; }
input[type=radio] + label {
position: relative; float: right; clear: none; display: block;
width: 18.4%; height: 120px; margin: 0 1% 0 1%; padding: 0;
outline: 0; cursor: pointer; background-color: green;
}
input[type=radio]#star-1 + label { margin: 0 1% 0 0; } input[type=radio]#star-5 + label { margin: 0 0 0 1%; }
fieldset > input[type=radio]:checked ~ label {
background-color: blue;
}
fieldset:hover > input[type=radio] + label:hover,
fieldset:hover > input[type=radio] + label:hover ~ label {
background-color: gold;
}
但是仍然存在问题...当您选择这些框时,它们会变成蓝色。并且您将鼠标悬停在蓝色停留处,而悬停在上方的部分为黄色。
鼠标悬停后如何重置蓝色?
【问题讨论】:
-
jsfiddle.net/5ntpom7a 对我来说这是可行的......
-
@SimonHänisch 一旦你点击它并突出显示,然后移除光标并尝试再次点击它就不起作用了。它还应该在
:hover上突出显示,而不是在点击上..甚至不知道为什么它在点击时有效,因为我没有编程:checked -
对我来说,点击后没有任何反应...
-
@SimonHänisch 查看jsfiddle.net/ypne7t2w 和编辑后的问题。
-
@Boris 请检查我在下面发布的解决方案。我想这就是你要找的。span>