I
I
iBird Rose2016-09-22 10:01:53
css
iBird Rose, 2016-09-22 10:01:53

How to work with svg sprites?

In general, I collected a sprite in gulp svg through symbol. it looks like:

<svg xmlns="http://www.w3.org/2000/svg">
    <symbol id="gamecontroller" viewBox="0 0 64 64"> ...     </symbol>
    <symbol id="icons-11" viewBox="0 0 65 65"> ...    </symbol>
</svg>

I'm trying to insert it through the background like this:
.my-icon {
  display: inline-block;
  vertical-align: middle;
  width: 100px;
  height: 100px;
  background: url('svg-symbols.svg#gamecontroller') no-repeat;
  background-size: contain;
}

but nothing comes out. what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2016-09-22
@petermzg

1. symbol is a descriptive element, it is not displayed, but it can be used in the use element

<svg xmlns="http://www.w3.org/2000/svg">
    <symbol id="gamecontroller" viewBox="0 0 64 64"> ...     </symbol>
    <symbol id="icons-11" viewBox="0 0 65 65"> ...    </symbol>
    <use xlink:href='#gamecontroller' />
  </svg>

2. How to implement the approach that you want (SVG fragment) is written here
3. With this approach, CSS styles are not applicable to SVG elements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question