4

How to take something like a star unicode \u2605 which is a star in html/css and only fill it half way instead of full.

Here is code:

<div class="starHalfFill">
 \u2605
</div>

My styles look like this thus far:

.starHalfFill {
  color: orange;
}
Taylor Austin
  • 5,407
  • 15
  • 58
  • 103

1 Answers1

0

Since this is colored by color and not background color we will have to do a little more work to get this filled halfway. Normally to fill a div half way you would do something like:

.starHalfFill {
  background: linear-gradient(to right, orange 50%, grey 50%);
}

but since this is a text based color we will have to target that.

     .star.star--non-filled {
        background: linear-gradient(to right, orange 50%, grey 50%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }

Those properties will target the text inside the div and also make the fill color transparent allowing the effect to work.

Taylor Austin
  • 5,407
  • 15
  • 58
  • 103