In my HTML document I have a which contains many items with
id
attributes, such as icon-x
.
Then I want to reuse these icons like
<div class=container> <svg><use xlink:href=#icon-x /></svg> </div>
However, the icons in this example may have different sizes in the source SVG. I want them to fit into the div.container
, but have white space around the svg in the container.
How can I tell it that I point to something and know that that thing defines the size of
so that when I do CSS like
. container svg { width: 100%; height: auto;}
Does it work the same as the tag?
with a viewBox attributeicon-x
Must be a symbol or nested svgWhen using
icon-x
, you can specify thewidth
heightfor the
代码> element. You can also specify different positions (x and y attributes) or different padding for
.
In the next example, I use
. You can optionally use nested svg's. In this case you might want to put it in