I am using this and was looking to add a new css class 'half' to the star selected class, to only fill half the star shape with the background color: #e54800
https://foundation.zurb.com/building-blocks/blocks/star-rating.html
So it would be: <div class="star selected half">
<div class="rating-block">
<div class="rating-block-rating" data-rating>
<div class="star selected">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="37" viewBox="0 0 40 37">
<polygon fill="none" points="272 30 260.244 36.18 262.489 23.09 252.979 13.82 266.122 11.91 272 0 277.878 11.91 291.021 13.82 281.511 23.09 283.756 36.18" transform="translate(-252)" />
</svg>
</div>
<div class="star">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="37" viewBox="0 0 40 37">
<polygon fill="none" points="272 30 260.244 36.18 262.489 23.09 252.979 13.82 266.122 11.91 272 0 277.878 11.91 291.021 13.82 281.511 23.09 283.756 36.18" transform="translate(-252)" />
</svg>
</div>
<div class="star">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="37" viewBox="0 0 40 37">
<polygon fill="none" points="272 30 260.244 36.18 262.489 23.09 252.979 13.82 266.122 11.91 272 0 277.878 11.91 291.021 13.82 281.511 23.09 283.756 36.18" transform="translate(-252)" />
</svg>
</div>
<div class="star">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="37" viewBox="0 0 40 37">
<polygon fill="none" points="272 30 260.244 36.18 262.489 23.09 252.979 13.82 266.122 11.91 272 0 277.878 11.91 291.021 13.82 281.511 23.09 283.756 36.18" transform="translate(-252)" />
</svg>
</div>
<div class="star">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="37" viewBox="0 0 40 37">
<polygon fill="none" points="272 30 260.244 36.18 262.489 23.09 252.979 13.82 266.122 11.91 272 0 277.878 11.91 291.021 13.82 281.511 23.09 283.756 36.18" transform="translate(-252)" />
</svg>
</div>
</div>
</div>
CSS:
.rating-block {
padding: 2px 5px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
.rating-block .ratings-type {
margin-right: 1rem;
margin-bottom: 0;
}
.rating-block .rating-block {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
margin-bottom: 2rem;
}
.rating-block .rating-block-rating {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.rating-block .star {
cursor: pointer;
stroke: #cc4b37;
}
.rating-block .rating-block-rating .star.selected polygon {
fill: #cc4b37;
}
.rating-block .rating-block-rating.is-voted .star polygon {
fill: #cc4b37;
}
.rating-block .rating-block-rating.is-voted .star.selected ~ .star polygon {
fill: transparent;
}
You can define a gradient using another svg (to avoid repeating it inside each one) and use the gradient with
fill
. You can easily adjust the % values or create more gradient if you want different otherfill
By the way here is an easier way to handle the rating without having to use the svg multiple time and define a gradient for the fill. You can use svg as background and simply control the width to control the rating:
Can also be improved with CSS variable: