P粉9086436112023-08-30 07:47:05
In SVG, you can use <linearGradient>
and <radialGradient>
. You're creating a progress bar, so depending on the layout, a radial gradient might be an option to create a "tapered gradient" (in quotes!), but it's really annoying to use.
A good alternative to built-in gradients might be to combine SVG and CSS. You can apply CSS styles to embedded SVG elements. As long as you just want a tapered gradient that can be applied to the SVG element, then mask it so it only shows up in the stroke or something. Here is an example:
svg { display: block; background-image: conic-gradient(from 180deg, green, orange, red); }
<svg width="300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> <defs> <mask id="m1"> <rect width="100" height="100" fill="white" /> <circle transform="rotate(120 50 50)" cx="50" cy="50" r="45" stroke="black" stroke-width="5" fill="none" stroke-dasharray="300 360" pathLength="360" /> </mask> </defs> <rect width="100" height="100" fill="white" mask="url(#m1)" /> </svg>