I'm creating a 5-star-review using SVG, but need to be able to display a value to 1-decimal-point (e.g. 2.5/5 or 4.2/5).
I also need to be able to display multiple 5-star-reviews on the same page.
I've been able to create the following (which displays 2.5) but the 50% on the second <rect> in the mask (which is required for the 0.5 on the 3rd star) is hardcoded...
<svg width="0" height="0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<defs>
<mask id="partial">
<rect x="0" y="0" width="64" height="64" fill="white" />
<rect x="50%" y="0" width="64" height="64" fill="black" />
</mask>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" id="star">
<path d="M32 2l-10 22l-20 2l15 14l-5 22l20-12l20 12l-5-22l15-14l-20-2Z"
stroke-width="3" stroke="#FFC800" />
</symbol>
</defs>
</svg>
<svg width="32" height="32" viewBox="0 0 64 64">
<use href="#star" fill="#FFC800"></use>
<use href="#star" fill="none"></use>
</svg>
<svg width="32" height="32" viewBox="0 0 64 64">
<use href="#star" fill="#FFC800"></use>
<use href="#star" fill="none"></use>
</svg>
<svg width="32" height="32" viewBox="0 0 64 64">
<use href="#star" fill="#FFC800" mask="url(#partial)"></use>
<use href="#star" fill="none"></use>
</svg>
<svg width="32" height="32" viewBox="0 0 64 64">
<use href="#star" fill="none"></use>
</svg>
<svg width="32" height="32" viewBox="0 0 64 64">
<use href="#star" fill="none"></use>
</svg>
Is there any way (preferably without javascript/jquery) that I can set the x="50%" on the <use> element?
Please remember that I will have multiple instances of the 5-star-review on the page at the same time, so it's not possible for me to dynamic set the x=50% on the <mask> because it will effect all instances.
What I don't want is to have to have 9 different id="partial10", id="partial20" <mask> elements.
I would like to do something like...
<use href="#star" fill="#FFC800" maskwidth="30%"></use>
