Star Rating Icons
The code in is overcomplicated and could be easily done with better tags than <div>s and can be interactive as well.
HTML
The two types of tags used in the following demo are:
<input id='ID' name='rad' type='radio'>
and
<label for='ID' class='star'>★</label>
There's an input and label for each star icon, the ID of the input is matched by the label [for] attribute. When an input/label pair is setup this way, they are associated so that when one is clicked the other is clicked as well. All inputs will be hidden and all labels will be styled.
CSS
Each input will be followed by the next label:
<label for='ID3' class='star'>★</label> // 1. User clicks
<input id='ID3' name='rad' type='radio'> // 2. Which puts this as: [name='rad']:checked
<label for='ID4' class='star'>★</label> /* 3. Any labels that occur from this point on
will be styled: ~ .star {color:navy}*/
<input id='ID4' name='rad' type='radio'>
<label for='ID5' class='star'>★</label>
So when this ruleset is in CSS:
[name='rad']:checked ~ .star { `color: navy` }
it will style the stars in two states: default color: gold (on) or color: navy (off).
Demo
Click a star and any stars to the right of it will turn off. Click to the left or right end where there are no stars and all stars will be turned off.
[name=rad] {
display: none
}
label {
display: inline-block;
outline: 0;
font-size: 10vh;
line-height: 1;
color: gold;
background: none;
transition: 0.6s;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: pointer;
}
[name=rad]:checked~.star {
color: navy;
transition: 0.6s;
}
#s0:checked~.star {
color: navy;
transition: 0.6s;
}
[name=rad]+label.star:hover {
color: cyan;
transition: 0.4s;
}
[name=rad]+label.star:active {
color: tomato;
transition: 0.4s;
}
<label for='s0' class='void'> </label>
<input id='s0' name='rad' type='radio' value='0'>
<label for='s1' class='star'>★</label>
<input id='s1' name='rad' type='radio' value='1'>
<label for='s2' class='star'>★</label>
<input id='s2' name='rad' type='radio' value='2'>
<label for='s3' class='star'>★</label>
<input id='s3' name='rad' type='radio' value='3'>
<label for='s4' class='star'>★</label>
<input id='s4' name='rad' type='radio' value='4'>
<label for='s5' class='star'>★</label>
<input id='s5' name='rad' type='radio' value='5' checked>
<label for='s0' class='void'> </label>