Answer the question
In order to leave comments, you need to log in
SVG icons as backgound?
Hello. A simple thing is needed. Embed svg icon as background for use in pseudo-elements. But you still need to do a color change on hover. I did not find any information on how to do this.
Thank you.
Ps and maybe there is something to automate the assembly into a sprite and insert it as a background and with positions for Gulp.
Answer the question
In order to leave comments, you need to log in
Your salvation is gulp-svg-sprite .
Able to collect sprites in four different modes, there is also a mode for css-background. Generates styles with already set icon coordinates in the sprite. For interactive svg background is not suitable.
I use the symbol mode, everything works like this:
currentColor
In the svg icon, write ( fill="currentColor"
or stroke="currentColor"
, depending on what needs to be painted) as the color of the required attribute .<svg>
<use style="color: rebeccapurple" xlink:href="id_элемента_спрайта"></use>
</svg>
color
is inherited inside the icon wherever the currentColor
. You can have fun with CSS! (transition to help you) Just solved this issue. Or rather, tried to decide - it is impossible to do it. There are crutches with filters and masks, but they are not supported everywhere, not always applicable, and generally crutches ( article ).
The only option is to inline the svg into the document, but that's also not a trivial task ( SO-1 , SO-2 , SO-3 ).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question