Home >Web Front-end >CSS Tutorial >How can I create a partially filled star shape with SVG?

How can I create a partially filled star shape with SVG?

Susan Sarandon
Susan SarandonOriginal
2024-11-09 11:43:02331browse

How can I create a partially filled star shape with SVG?

Creating and Partially Filling a Star Shape with SVG

To create a stroke on the outside of the star, you should tweak the stroke-linecap property. Here's an updated version of your code:

<br><svg height="210" width="500"><br>  <polygon points="100,10 40,198 190,78 10,78 160,198" stroke-linecap="round"></svg><br>

Now, let's partially fill the star shape. You can use CSS filters to achieve this effect. A filter called "fillpartial" can be defined as follows:

<br><defs><br>  <filter><pre class="brush:php;toolbar:false"><feFlood x="0%" y="0%" width="100%" height="100%" flood-color="red" />
<feOffset dy="0.5">
  <animate attributeName="dy" from="1" to=".5" dur="3s" />
</feOffset>
<feComposite operator="in" in2="SourceGraphic" />
<feComposite operator="over" in2="SourceGraphic" /></p>
<p></filter><br></defs><br>

Then, you can apply this filter to your star shape like this:

<br><polygon filter="url(#fillpartial)" points="165.000, 185.000, 188.511, 197.361, 184.021, 171.180,<br> 203.042, 152.639,<br> 176.756, 148.820,<br> 165.000, 125.000,<br> 153.244, 148.820,<br> 126.958, 152.639,<br> 145.979, 171.180,<br> 141.489, 197.361,<br> 165.000, 185.000">

This will result in a star shape that is filled up to the halfway point, creating a half-filled effect. You can modify the stop-color and stop-opacity values of the element to change the color and transparency of the filled area.

The above is the detailed content of How can I create a partially filled star shape with SVG?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn