A
A
AlexFlowint2019-10-10 11:21:25
Sprites
AlexFlowint, 2019-10-10 11:21:25

How to correctly specify a link to an svg sprite through the img tag or through the css background/background-image property?

Made sprite automation using gulp-svg-sprite.
Everything works fine if you use this method:

<svg class="icon-name">
    <use xlink:href="./img/sprite-icons.svg#name" />
</svg>

on when I want to use sprite via img tag: or via css background, background-image properties like so:
<img src="./img/sprite-icons.svg#name" alt="" />
.icon {
    background-image: url('./img/sprite-icons.svg#name')
}

then I can’t display the icon, but there are no errors in the console.
Tell me how to correctly prescribe the paths in the last two options, or can they not be done this way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question