S
S
Space Around2020-02-24 05:47:03
Layout
Space Around, 2020-02-24 05:47:03

How to use color and pattern together in SVG?

An irregularly shaped figure is created, filled with a gradient, but how to use a pattern as well? It should be on top of the gradient and inside the

HTML shape:

<svg id="svg" viewBox="0 0 1000 1000">
    <defs>
        <linearGradient id="lgrad" x1="7%" y1="0%" x2="93%" y2="100%" >
            <stop offset="0%" style="stop-color:rgb(255,29,139);stop-opacity:1" />
            <stop offset="100%" style="stop-color:rgb(255,255,255);stop-opacity:1" />
        </linearGradient>
        <pattern id="pattern-bg" x="0" y="0" width="20" height="20" viewBox ='0 0 80 80' patternUnits="userSpaceOnUse">
            <circle fill="0x0" cx="3" cy="3" r="2.5"></circle>
        </pattern>
    </defs>
    <path id="path3"></path>
</svg>


CSS:
#path3 {
    fill: url(#lgrad);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
A person from Kazakhstan, 2020-02-24
@viksnamax

https://stackoverflow.com/a/60395056/6339052
In English SO they gave one single correct answer ... I'm nick and really a task that I did not know

<svg id="svg" viewBox="0 0 1000 1000">
    <defs>
        <linearGradient id="grad" x1="7%" y1="0%" x2="93%" y2="100%" >
            <stop offset="0%" style="stop-color:rgb(255,29,139);stop-opacity:1" />
            <stop offset="100%" style="stop-color:rgb(255,255,255);stop-opacity:1" />
        </linearGradient>
        <pattern id="bg" x="0" y="0" width="20" height="20" viewBox ='0 0 80 80' patternUnits="userSpaceOnUse">
            <circle fill="0x0" cx="3" cy="3" r="2.5"></circle>
        </pattern>

        <pattern id="both" width="100%" height="100%">
           <rect width="100%" height="100%" fill="url(#grad)"/>
           <rect width="100%" height="100%" fill="url(#bg)"/>
        </pattern>
    </defs>
  <g>
    <path id="path3" d="M0,0 1000,0 1000,1000 0,1000z"  fill="url(#both)"></path>
  </g>
</svg>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question