我创建了一个5星评级系统。我的CSS设置为显示固定在屏幕上的灰色背景星星。当出现蓝色星星盘旋时,虽然这些星星居中并伸出,例如当我选择一颗星时,中间星变成黄金而不是最左边的灰星,同样,如果我选择2颗星,两颗金星出现在第二和第四颗灰星,灰色星星在背景中仍然可见。这看起来很不整洁。CSS 5星级评分系统,星级问题
任何人都可以告诉我如何改变我的代码来转换选择黄金的实际星星?
我的星星图片是stars.png,其中一张图片分别有灰色,蓝色和金色星星。
我对css的知识有限。我试图改变CSS的一个接一个,例如宽度或像素的多个组件,但无济于事。
这是我的CSS。
form .stars {
background: url("stars.png") repeat-x 0 0;
width: 150px;
margin: 0 auto;
}
form .stars input[type="radio"] {
position: absolute;
opacity: 0;
filter: alpha(opacity=0);
}
form .stars input[type="radio"].star-5:checked ~ span {
width: 100%;
}
form .stars input[type="radio"].star-4:checked ~ span {
width: 80%;
}
form .stars input[type="radio"].star-3:checked ~ span {
width: 60%;
}
form .stars input[type="radio"].star-2:checked ~ span {
width: 40%;
}
form .stars input[type="radio"].star-1:checked ~ span {
width: 20%;
}
form .stars label {
display: block;
width: 30px;
height: 30px;
margin: 0!important;
padding: 0!important;
text-indent: -999em;
float: left;
position: relative;
z-index: 10;
background: transparent!important;
cursor: pointer;
}
form .stars label:hover ~ span {
background-position: 0 -30px;
}
form .stars label.star-5:hover ~ span {
width: 100% !important;
}
form .stars label.star-4:hover ~ span {
width: 80% !important;
}
form .stars label.star-3:hover ~ span {
width: 60% !important;
}
form .stars label.star-2:hover ~ span {
width: 40% !important;
}
form .stars label.star-1:hover ~ span {
width: 20% !important;
}
form .stars span {
display: block;
width: 0;
position: relative;
top: 0;
left: 0;
height: 30px;
background: url("stars.png") repeat-x 0 -60px;
-webkit-transition: -webkit-width 0.5s;
-moz-transition: -moz-width 0.5s;
-ms-transition: -ms-width 0.5s;
-o-transition: -o-width 0.5s;
transition: width 0.5s;
}
嗯,你可以删除的行号? –
Hi @JacobGray。我已根据要求删除了行号。他们没有按照我的实际代码 – scubbastevie
本质上,它归结为更改'background-position'属性。您移动背景图像,以便显示您想要显示的恒星的“状态”。我无法提供确切的代码,因为我不知道你的星形精灵是什么样的。 – Scott