Cleaner way to use HTML SVG elements? - html

I have several SVG elements that are under various HTML elements. As you can see in the example below they take up a lot of space and clutter the html.
I'm wondering if anyone has any suggestions on the best way to clean this up. I could use partial HTML views for each SVG element, but that's a bit overboard and all I can think of.
<div id="canvasControl" class="cnvsControl" hidden="hidden" style="height:36px; background-color:black; position:relative;margin-top:-36px;z-index:9999;opacity: 0.2;">
<div class="imageUpload canvasControlButton alignLeft" style="height:36px; position:relative;" title="Open File" id="btnOpenFile" name="btnOpenFile" onclick="snes_readfile(this)">
<label for="btnFileImport" style="position:absolute;top:5px;">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="openFolder1" d="M416 480l96-256h-416l-96 256zM64 192l-64 288v-416h144l64 64h208v64z"></path>
</defs>
<use fill="#fff" xlink:href="#openFolder1"></use>
</svg>
</label>
<input id="btnFileImport" type="file" onchange="snes_readfile(this)" />
</div>
<button class="canvasControlButton alignRight" title="Full screen" id="btnFullScreen" name="btnFullScreen">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outFullArrow1" d="M512 0h-208l80 80-96 96 48 48 96-96 80 80z"></path>
<path id="outFullArrow2" d="M512 512v-208l-80 80-96-96-48 48 96 96-80 80z"></path>
<path id="outFullArrow3" d="M0 512h208l-80-80 96-96-48-48-96 96-80-80z"></path>
<path id="outFullArrow4" d="M0 0v208l80-80 96 96 48-48-96-96 80-80z"></path>
</defs>
<use fill="#fff" xlink:href="#outFullArrow1"></use>
<use fill="#fff" xlink:href="#outFullArrow2"></use>
<use fill="#fff" xlink:href="#outFullArrow3"></use>
<use fill="#fff" xlink:href="#outFullArrow4"></use>
</svg>
</button>
<button class="canvasControlButton alignRight" title="Bigger Screen" id="btnChangeScreenSize" name="btnChangeScreenSize">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outArrow1" d="M512 0v208l-80-80-96 96-48-48 96-96-80-80zM224 336l-96 96 80 80h-208v-208l80 80 96-96z"></path>
</defs>
<use fill="#fff" xlink:href="#outArrow1"></use>
</svg>
</button>

You can create a separate the SVG file and then link it to your HTML document like this:
Create SVG files named
one.svg :
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="openFolder1" d="M416 480l96-256h-416l-96 256zM64 192l-64 288v-416h144l64 64h208v64z"></path>
</defs>
<use fill="#fff" xlink:href="#openFolder1"></use>
</svg>
two.svg
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outFullArrow1" d="M512 0h-208l80 80-96 96 48 48 96-96 80 80z"></path>
<path id="outFullArrow2" d="M512 512v-208l-80 80-96-96-48 48 96 96-80 80z"></path>
<path id="outFullArrow3" d="M0 512h208l-80-80 96-96-48-48-96 96-80-80z"></path>
<path id="outFullArrow4" d="M0 0v208l80-80 96 96 48-48-96-96 80-80z"></path>
</defs>
<use fill="#fff" xlink:href="#outFullArrow1"></use>
<use fill="#fff" xlink:href="#outFullArrow2"></use>
<use fill="#fff" xlink:href="#outFullArrow3"></use>
<use fill="#fff" xlink:href="#outFullArrow4"></use>
</svg>
three.svg
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outArrow1" d="M512 0v208l-80-80-96 96-48-48 96-96-80-80zM224 336l-96 96 80 80h-208v-208l80 80 96-96z"></path>
</defs>
<use fill="#fff" xlink:href="#outArrow1"></use>
</svg>
Then edit your HTML to :
<div id="canvasControl" class="cnvsControl" hidden="hidden" style="height:36px; background-color:black; position:relative;margin-top:-36px;z-index:9999;opacity: 0.2;">
<div class="imageUpload canvasControlButton alignLeft" style="height:36px; position:relative;" title="Open File" id="btnOpenFile" name="btnOpenFile" onclick="snes_readfile(this)">
<label for="btnFileImport" style="position:absolute;top:5px;">
<object>
<embed scr="one.svg">
</object>
</label>
<input id="btnFileImport" type="file" onchange="snes_readfile(this)" />
</div>
<button class="canvasControlButton alignRight" title="Full screen" id="btnFullScreen" name="btnFullScreen">
<object>
<embed scr="two.svg">
</object>
</button>
<button class="canvasControlButton alignRight" title="Bigger Screen" id="btnChangeScreenSize" name="btnChangeScreenSize">
<object>
<embed scr="three.svg">
</object>
</button>
Hope it helped and don't forget to validate the answer if it's resolve your issue.

Related

how to mask an svg shape to an svg image

So basically I have a triangular shape and I want to mask it in an image/gif.
<svg width="209" height="143" viewBox="0 0 209 143" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z" fill="black"/>
</svg>
<div class="clipSvg2">
<svg viewBox="0 0 300 300" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<mask id="mask11">
<!-- <svg width="209" height="143" viewBox="0 0 209 143" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z" fill="black"/>
</svg>
-->
</mask>
</defs>
//Here add some mask=url(#mask11)
<image
width="100%" height="100%" xlink:href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU69UnQwUGs3VTS51AEM2MRTHED0PRl0rMLVw3hdS_95xNdTPqY5_7E3N-pzgp49lrdkY&usqp=CAU"></image>
</svg>
</div>
As you see I'm trying to mask the mask11 in my image but I can't do that..I've search a lot here and its not really working I don't know how or what to do about it can anyone help me? Thanks a lot.
I'm not sure what it should look like, but here are two examples. The first uses a clip-path. With the clip-rule="evenodd" it is only the "frame" that shows.
The second is a mask. In the mask the path has a white fill – that is what makes the image show.
In both cases I made the viewBox the same aspect ratio as the image to make the image take up the entire space of the SVG.
<svg width="300" viewBox="0 0 284 178" xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id="cp1">
<path clip-rule="evenodd"
d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z" />
</clipPath>
</defs>
<image width="100%" height="100%"
href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU69UnQwUGs3VTS51AEM2MRTHED0PRl0rMLVw3hdS_95xNdTPqY5_7E3N-pzgp49lrdkY&usqp=CAU"
clip-path="url(#cp1)"/>
</svg>
<svg width="300" viewBox="0 0 284 178" xmlns="http://www.w3.org/2000/svg">
<defs>
<mask id="m1">
<path d="M104.5 0L0.143921 142.5H208.856L104.5 0ZM104.5 10.1551L11.9747 136.5H197.025L104.5 10.1551Z"
fill="white"/>
</mask>
</defs>
<image width="100%" height="100%"
href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQU69UnQwUGs3VTS51AEM2MRTHED0PRl0rMLVw3hdS_95xNdTPqY5_7E3N-pzgp49lrdkY&usqp=CAU"
mask="url(#m1)"/>
</svg>

On hover a tag title is not working as tool-tip when i put svg inside a Tag

I need Grid View on hover a tag as tooltip.
<a href="javascript:;" title="Grid View">
<svg width="24px" height="24px" viewBox="0 0 25 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>F97BF56E-2918-48BD-A2B7-2FA7C41F6C7F</title>
<desc>Created with sketchtool.</desc>
<g id="Asset-Artboard-Page" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="atoms-/-👍-/-view-grid" transform="translate(0.689655, 0.000000)" fill="#756280">
<path d="M3,11 L11,11 L11,3 L3,3 M3,21 L11,21 L11,13 L3,13 M13,21 L21,21 L21,13 L13,13 M13,3 L13,11 L21,11 L21,3" id="grid-view-list"></path>
</g>
</g>
</svg>
</a>
Change the text in title tag of your svg to 'Grid View'.
Or just delete the title tage outright.
So like this:
<a href="javascript:;" title="Grid View">
<svg width="24px" height="24px" viewBox="0 0 25 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<desc>Created with sketchtool.</desc>
<g id="Asset-Artboard-Page" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="atoms-/-👍-/-view-grid" transform="translate(0.689655, 0.000000)" fill="#756280">
<path d="M3,11 L11,11 L11,3 L3,3 M3,21 L11,21 L11,13 L3,13 M13,21 L21,21 L21,13 L13,13 M13,3 L13,11 L21,11 L21,3" id="grid-view-list"></path>
</g>
</g>
</svg>
</a>

How to set viewBox attribute for svg using 'use' tag?

..
<svg>
<defs>
<symbol id="svg-rating-star">
<!-- svg content -->
</symbol>
</defs>
</svg>
<span>case 1:</span>
<svg class="svg-rating-star" width="50" height="10" viewBox="10 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star"></use>
</svg>
<svg class="svg-rating-star" width="50" height="10" viewBox="20 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star"></use>
</svg>
<span>case 2:</span>
<svg class="svg-rating-star" width="50" height="10" viewBox="10 0 50 10">
<!-- svg content -->
</svg>
<svg class="svg-rating-star" width="50" height="10" viewBox="20 0 50 10">
<!-- svg content -->
</svg>
more specific in demo
in case 1, svg's viewBox is not working as i expected. its viewport does move but the rest stars are not shown.
if the svg's content is set within it like case 2, it works perfectly.
how to set viewBox for the svgs in case 1?
The problem you're having is because the width value of a <use> element defaults to "100%" if it is not specified. In this case that means "50" because that's what's specified on the two <svg> elements.
Because it is only 50, that means that only the five gold stars will ever be shown. Even when you change the viewBox, you are only just shifting those five gold stars left.
The solution is to specify a width="100" on your <use> elements so that all the stars are made visible.
.svg-rating-star .svg-rating-star-active {
fill: #fdcc00;
}
.svg-rating-star .svg-rating-star-inactive {
fill: #d1d1d1;
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
<defs>
<symbol id="svg-rating-star" class="svg-rating-star">
<g id="svg-rating-star_svg-rating-star">
<polygon class="svg-rating-star-active" points="4.732,0 6.194,2.963 9.463,3.438 7.098,5.745 7.656,9 4.732,7.463 1.807,9 2.366,5.745 0,3.438 3.269,2.963 "></polygon>
<polygon class="svg-rating-star-active" points="14.732,0 16.194,2.963 19.463,3.438 17.098,5.745 17.656,9 14.732,7.463 11.807,9 12.366,5.745 10,3.438 13.269,2.963 "></polygon>
<polygon class="svg-rating-star-active" points="24.732,0 26.194,2.963 29.463,3.438 27.098,5.745 27.656,9 24.732,7.463 21.807,9 22.365,5.745 20,3.438 23.27,2.963 "></polygon>
<polygon class="svg-rating-star-active" points="34.732,0 36.194,2.963 39.463,3.438 37.098,5.745 37.656,9 34.732,7.463 31.807,9 32.365,5.745 30,3.438 33.27,2.963 "></polygon>
<polygon class="svg-rating-star-active" points="44.732,0 46.194,2.963 49.463,3.438 47.098,5.745 47.656,9 44.732,7.463 41.807,9 42.365,5.745 40,3.438 43.27,2.963 "></polygon>
<polygon class="svg-rating-star-inactive" points="54.732,0 56.194,2.963 59.463,3.438 57.098,5.745 57.656,9 54.732,7.463 51.807,9 52.365,5.745 50,3.438 53.27,2.963 "></polygon>
<polygon class="svg-rating-star-inactive" points="64.732,0 66.194,2.963 69.463,3.438 67.098,5.745 67.656,9 64.732,7.463 61.807,9 62.365,5.745 60,3.438 63.27,2.963 "></polygon>
<polygon class="svg-rating-star-inactive" points="74.732,0 76.194,2.963 79.463,3.438 77.098,5.745 77.656,9 74.732,7.463 71.807,9 72.365,5.745 70,3.438 73.27,2.963 "></polygon>
<polygon class="svg-rating-star-inactive" points="84.732,0 86.194,2.963 89.463,3.438 87.098,5.745 87.656,9 84.732,7.463 81.807,9 82.365,5.745 80,3.438 83.27,2.963 "></polygon>
<polygon class="svg-rating-star-inactive" points="94.732,0 96.194,2.963 99.463,3.438 97.098,5.745 97.656,9 94.732,7.462 91.807,9 92.365,5.745 90,3.438 93.27,2.963 "></polygon>
</g>
</symbol>
</defs>
</svg>
<svg class="svg-rating-star" width="50" height="10" viewBox="10 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" width="100"/>
</svg>
<br/>
<svg class="svg-rating-star" width="50" height="10" viewBox="20 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" width="100"/>
</svg>
I think that the only one way here is to duplicate one path to different id's:
.svg-rating-star-inactive {
fill: #d1d1d1;
}
.svg-rating-star-active {
fill: #fdcc00;
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display: none">
<defs>
<symbol id="svg-rating-star">
<polygon points="4.732,0 6.194,2.963 9.463,3.438 7.098,5.745 7.656,9 4.732,7.463 1.807,9 2.366,5.745 0,3.438 3.269,2.963 "></polygon>
</symbol>
<symbol id="svg-rating-star0">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="0" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="10" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="20" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="30" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="40" class="svg-rating-star-inactive"></use>
</symbol>
<symbol id="svg-rating-star1">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="0" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="10" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="20" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="30" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="40" class="svg-rating-star-inactive"></use>
</symbol>
<symbol id="svg-rating-star2">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="0" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="10" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="20" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="30" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="40" class="svg-rating-star-inactive"></use>
</symbol>
<symbol id="svg-rating-star3">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="0" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="10" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="20" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="30" class="svg-rating-star-inactive"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="40" class="svg-rating-star-inactive"></use>
</symbol>
<symbol id="svg-rating-star4">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="0" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="10" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="20" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="30" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="40" class="svg-rating-star-inactive"></use>
</symbol>
<symbol id="svg-rating-star5">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="0" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="10" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="20" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="30" class="svg-rating-star-active"></use>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star" x="40" class="svg-rating-star-active"></use>
</symbol>
</defs>
</svg>
<br/>
<svg width="50" height="10" viewBox="0 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star0"></use>
</svg>
<br/>
<svg width="50" height="10" viewBox="0 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star1"></use>
</svg>
<br/>
<svg width="50" height="10" viewBox="0 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star2"></use>
</svg>
<br/>
<svg width="50" height="10" viewBox="0 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star3"></use>
</svg>
<br/>
<svg width="50" height="10" viewBox="0 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star4"></use>
</svg>
<br/>
<svg width="50" height="10" viewBox="0 0 50 10">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-rating-star5"></use>
</svg>

Hyperlink SVG <use> tags

I am unable to hyperlink an icon using a <use> tag. I created an SVG icon system and saved it on an external source (https://css-tricks.com/lodge/svg/16-svg-icon-system-external-source/). I have attempted a couple of options and had no success.
HTML Code:
<svg class="icon-LinkedIn">
<use xlink:href="symbol-defs.svg#icon-LinkedIn">
<a href='https://www.linkedin.com/'></a>
</use>
</svg>
Attempts:
1.
<a href='https://www.linkedin.com/'>
<use xlink:href="symbol-defs.svg#icon-LinkedIn">
</use>
</a>
</svg>
2.
<use xlink:href="symbol-defs.svg#icon-LinkedIn"
xlink:href='https://www.linkedin.com/'>
</use>
</svg>
3.
<svg class="icon-LinkedIn">
<use xlink:href="symbol-defs.svg#icon-LinkedIn"
xlink:href='https://www.linkedin.com/'>
</use>
</svg>
SVG:
<svg style="position: absolute; width: 0; height: 0;" width="0" height="0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-LinkedIn" viewBox="0 0 32 32">
<title>LinkedIn</title>
<path class="path1" d="M16 32c-8.837 0-16-7.163-16-16s7.163-16 16- 16c8.837 0 16 7.163 16 16s-7.163 16-16 16zM16 30.080c7.776 0 14.080-6.304 14.080-14.080s-6.304-14.080-14.080-14.080c-7.776 0-14.080 6.304-14.080 14.080s6.304 14.080 14.080 14.080zM8.96 12.876v9.306h3.014v-9.306h-3.014zM10.665 8.32c-1.031 0-1.705 0.695-1.705 1.607 0 0.894 0.654 1.608 1.666 1.608h0.019c1.051 0 1.706-0.715 1.706-1.608-0.020-0.912-0.655-1.607-1.686-1.607zM19.569 12.876c-1.6 0-2.317 0.903-2.717 1.537v-1.318h-3.015c0.040 0.873 0 9.306 0 9.306h3.015v-5.197c0-0.278 0.020-0.556 0.099-0.755 0.218-0.556 0.714-1.131 1.547-1.131 1.091 0 1.527 0.853 1.527 2.104v4.979h3.014l0-5.336c0-2.858-1.487-4.189-3.471-4.189z"></path>
</symbol>
</defs>
</svg>
Try this:
<a href='https://www.linkedin.com/'>
<svg class="icon-LinkedIn">
<use xlink:href="symbol-defs.svg#icon-LinkedIn">
</use>
</svg>
</a>
wrap anchor tag on svg
jsFiddle

SVG defintions and "use" produce overlapping graphics

The definitions look like this:
<svg style="display: none;">
<defs>
<symbol id="icon-1" viewBox="0 0 32 32">
<path ...
</symbol>
<symbol id="icon-2" viewBox="0 0 32 32">
<path ...
</symbol>
...
</svg>
and they are used like this:
<svg class="icon"><use xlink:href="#icon-2" /></svg>
The icons are shown but all of them at once, overlapped. I thought it's because they have the same viewBox, so I changed the y coordinate for each icon like this:
0 0 32 32
0 32 32 32
0 64 32 32
...
But then no icon shows up. Am I missing something?
It would help if you could provide a Minimal, Complete, and Verifiable example in your question. I can't see anything wrong with this approach. The following example works just fine:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
style="display: none;">
<defs>
<symbol id="icon-1" viewBox="0 0 32 32">
<circle cx="16" cy="16" r="12" fill="#f00" />
</symbol>
<symbol id="icon-2" viewBox="0 0 32 32">
<path d="m4 4h24v24h-24v-24z" fill="#00f" />
</symbol>
</defs>
</svg>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="32" height="32" viewBox="0 0 32 32">
<use xlink:href="#icon-1" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="32" height="32" viewBox="0 0 32 32">
<use xlink:href="#icon-2" />
</svg>