Is it possible to set a background-image
for an SVG <path>
element?
For instance, if I set the element class="wall"
, the CSS style .wall {fill: red;}
works, but .wall{background-image: url(wall.jpg)}
does not, neither .wall {background-color: red;}
.
The answer by "robertc" is svg - and this is similar to what is used by d3.js path code. I managed to create dynamic def's for d3.js paths by applying the following.
I managed to get it working by defining it as the following
You can do it by making the background into a pattern:
Adjust the width and height according to your image, then reference it from the path like this:
Working example