源码
<span class="star__container">
<input type="radio" name="rating" value="1" id="star-1" class="star__radio visuhide">
<input type="radio" name="rating" value="2" id="star-2" class="star__radio visuhide">
<input type="radio" name="rating" value="3" id="star-3" class="star__radio visuhide">
<input type="radio" name="rating" value="4" id="star-4" class="star__radio visuhide">
<input type="radio" name="rating" value="5" id="star-5" class="star__radio visuhide">
<label class="star__item" for="star-1"><span class="visuhide">1 star</span></label>
<label class="star__item" for="star-2"><span class="visuhide">2 stars</span></label>
<label class="star__item" for="star-3"><span class="visuhide">3 stars</span></label>
<label class="star__item" for="star-4"><span class="visuhide">4 stars</span></label>
<label class="star__item" for="star-5"><span class="visuhide">5 stars</span></label>
</span>
<style>
html,body {
height: 100%;
font-size: 32px;
}
body {
display: flex;
margin: 0;
background-color: #e6e6e6;
}
.visuhide {
position: absolute !important;
overflow: hidden;
width: 1px;
height: 1px;
clip: rect(1px, 1px, 1px, 1px);
}
.star__container:hover .star__item,
.star__radio:checked~.star__item {
-webkit-filter: grayscale(0);
filter: grayscale(0);
}
.star__container:not(:hover)>.star__radio:nth-of-type(1):checked~.star__item:nth-of-type(1)~.star__item,
.star__container:not(:hover)>.star__radio:nth-of-type(2):checked~.star__item:nth-of-type(2)~.star__item,
.star__container:not(:hover)>.star__radio:nth-of-type(3):checked~.star__item:nth-of-type(3)~.star__item,
.star__container:not(:hover)>.star__radio:nth-of-type(4):checked~.star__item:nth-of-type(4)~.star__item,
.star__container:not(:hover)>.star__radio:nth-of-type(5):checked~.star__item:nth-of-type(5)~.star__item,
.star__item,
.star__item:hover~.star__item {
-webkit-filter: grayscale(1);
filter: grayscale(1);
}
.star__radio:nth-of-type(1):checked~.star__item:nth-of-type(1)::before {
-webkit-transform: scale(1.5);
transform: scale(1.5);
transition-timing-function: cubic-bezier(0.5, 1.5, 0.25, 1);
}
.star__radio:nth-of-type(2):checked~.star__item:nth-of-type(2)::before {
-webkit-transform: scale(1.5);
transform: scale(1.5);
transition-timing-function: cubic-bezier(0.5, 1.5, 0.25, 1);
}
.star__radio:nth-of-type(3):checked~.star__item:nth-of-type(3)::before {
-webkit-transform: scale(1.5);
transform: scale(1.5);
transition-timing-function: cubic-bezier(0.5, 1.5, 0.25, 1);
}
.star__radio:nth-of-type(4):checked~.star__item:nth-of-type(4)::before {
-webkit-transform: scale(1.5);
transform: scale(1.5);
transition-timing-function: cubic-bezier(0.5, 1.5, 0.25, 1);
}
.star__radio:nth-of-type(5):checked~.star__item:nth-of-type(5)::before {
-webkit-transform: scale(1.5);
transform: scale(1.5);
transition-timing-function: cubic-bezier(0.5, 1.5, 0.25, 1);
}
.star__container {
display: flex;
margin: auto;
border-radius: .25em;
background-color: #00a39b;
box-shadow: 0 0.25em 1em rgba(0, 0, 0, 0.25);
transition: box-shadow .3s ease;
}
.star__container:focus-within {
box-shadow: 0 0.125em 0.5em rgba(0, 0, 0, 0.5);
}
.star__item {
display: inline-flex;
width: 1.25em;
height: 1.5em;
}
.star__item::before {
content: "⭐️";
display: inline-block;
margin: auto;
font-size: .75em;
vertical-align: top;
backface-visibility: hidden;
-webkit-transform-origin: 50% 33.3%;
transform-origin: 50% 33.3%;
transition: -webkit-transform .3s ease-out;
transition: transform .3s ease-out;
transition: transform .3s ease-out, -webkit-transform .3s ease-out;
}
</style>