G
G
Genri_Rus2019-09-22 19:20:21
css
Genri_Rus, 2019-09-22 19:20:21

How to make svg sprite friends with sass variables?

Let's say we have an svg sprite

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <symbol id="menu-white" viewBox="0 0 42 42">   
        <circle cx="20" cy="20" r="19" stroke="white" stroke-width="2"/>
            <circle cx="19.5" cy="10.5" r="2.5" fill="var($color-white)"/>
            <circle cx="19.5" cy="19.5" r="2.5" fill="var($color-white)"/>
            <circle cx="19.5" cy="28.5" r="2.5" fill="var($color-white)"/>
    </symbol>
</svg>

In sass, a variable is declared accordingly: $color-white: #fff
How can I pass a variable $color-whiteto svg?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RAX7, 2019-09-22
@Genri_Rus

https://css-tricks.com/cascading-svg-fill-color/

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" display="none">
  <symbol id="menu-white" viewBox="0 0 42 42">
    <circle cx="20" cy="20" r="19" stroke="white" stroke-width="2"/>
    <circle cx="19.5" cy="10.5" r="2.5" fill="currentColor"/>
    <circle cx="19.5" cy="19.5" r="2.5" fill="currentColor"/>
    <circle cx="19.5" cy="28.5" r="2.5" fill="currentColor"/>
  </symbol>
</svg>

<svg class="ico" width="42" height="42"><use xlink:href="#menu-white"/></svg>

$color-white: #fff;

.ico {
  color: $color-white;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question