I got an SVG from a designer of which I'd like to set the color through CSS from outside of the SVG. I managed to overwrite part of the colors, but not all. What would I need to do to have the icon unfilled, with red lines over the grey background? Ideally without modifying the SVG because there are plenty of them with similar structure.
html {
background-color: #eeeeee;
}
.icon{
height: 6rem;
width: 6rem;
}
svg {
fill:red;
}
<html>
<div class="icon">
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.1.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" baseProfile="basic" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" viewBox="0 0 76.5 76.5" xml:space="preserve">
<style type="text/css">
.st0{display:none;}
.st1{fill:none;stroke:#000000;stroke-width:2;}
.st2{fill:#FFFFFF;}
.st3{fill:none;stroke:#FFFFFF;stroke-width:5;}
.st4{fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;}
.st5{display:inline;}
.st6{font-family:'Akkurat-Bold';}
.st7{font-size:7.0024px;}
.st8{display:inline;fill:#2B3427;}
.st9{fill:none;stroke:#2B3427;stroke-width:2;}
.st10{fill:none;stroke:#2B3427;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;}
.st11{display:inline;fill:#FFFFFF;}
.st12{fill:#2B3427;}
</style>
<g id="Vorlagen" class="st0">
</g>
<g id="Kreis_Black">
<path d="M38.3,4.8c18.4,0,33.4,15,33.4,33.4s-15,33.4-33.4,33.4S4.8,56.7,4.8,38.3S19.8,4.8,38.3,4.8 M38.3,2.8
C18.7,2.8,2.8,18.7,2.8,38.3s15.9,35.4,35.4,35.4s35.4-15.9,35.4-35.4S57.8,2.8,38.3,2.8L38.3,2.8z"/>
<path d="M38.3,4.8c18.4,0,33.4,15,33.4,33.4s-15,33.4-33.4,33.4S4.8,56.7,4.8,38.3S19.8,4.8,38.3,4.8 M38.3,2.8
C18.7,2.8,2.8,18.7,2.8,38.3s15.9,35.4,35.4,35.4s35.4-15.9,35.4-35.4S57.8,2.8,38.3,2.8L38.3,2.8z"/>
</g>
<g id="Illu">
<g>
<path class="st1" d="M35.2,43.3c-1.5,1-9.1,3.6-14.7-1.1c-4-3.3-4.4-8.7-3.6-24.9c9.5-0.9,17.4,0.9,22,5c4.1,3.6,3.9,8.6,4.3,11.2
C43.6,36.5,39.5,40.4,35.2,43.3z"/>
<path class="st2" d="M44.8,41.6c9.7,6,18.3-7.2,20.2-15.9c-5.5-3.6-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6"/>
<path class="st3" d="M44.8,41.6c9.7,6,18.3-7.2,20.2-15.9c-5.5-3.6-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6z"/>
<path class="st2" d="M44.8,41.6C57.2,51.9,63,36.7,64.9,25.7c-8.2-3.9-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6"/>
<path class="st1" d="M44.8,41.6C57.2,51.9,63,36.7,64.9,25.7c-8.2-3.9-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6z"/>
<path class="st4" d="M22.7,22.6c0,0,14.8,6,11.3,43.2c0,0,12.4-31.6,24-36.1"/>
</g>
<rect x="21.1" y="47.3" class="st2" width="32.6" height="8.1"/>
</g>
<g id="Typo" class="st0">
<text transform="matrix(1 0 0 1 25.4238 53.8332)" class="st5 st6 st7">VEGAN</text>
</g>
<g id="Typo_Gepfadet">
<g>
<path d="M28.1,53.8h-1l-1.6-5h1l1.2,3.8l1.2-3.8h0.9L28.1,53.8z"/>
<path d="M30.8,53.8v-5h3.5v0.8h-2.6v1.2H34v0.8h-2.3V53h2.6v0.8H30.8z"/>
<path d="M38.9,53.8l-0.1-0.5c-0.1,0.3-0.6,0.6-1.2,0.6c-0.6,0-1.1-0.1-1.5-0.6c-0.5-0.5-0.6-1.2-0.6-2s0.1-1.5,0.6-2
c0.4-0.4,0.9-0.6,1.5-0.6c0.6,0,1.1,0.2,1.5,0.6c0.2,0.3,0.4,0.6,0.5,1h-0.9c0-0.2-0.1-0.3-0.2-0.5c-0.2-0.2-0.4-0.3-0.8-0.3
c-0.3,0-0.6,0.1-0.8,0.3c-0.3,0.4-0.4,1-0.4,1.4s0,1.1,0.4,1.5c0.2,0.2,0.5,0.3,0.8,0.3c0.3,0,0.6-0.1,0.7-0.3
c0.3-0.3,0.3-0.6,0.3-1h-1.2v-0.8h2.1v2.7H38.9z"/>
<path d="M44,53.8l-0.3-1h-2l-0.3,1h-0.9l1.7-5h1l1.7,5H44z M42.7,50L42,52.1h1.4L42.7,50z"/>
<path d="M49.1,53.8l-2.2-3.4v3.4H46v-5h1l2.1,3.4v-3.4H50v5H49.1z"/>
</g>
</g>
<g id="Ikons_x5F_Grün" class="st0">
<path class="st8" d="M38.3,4.8c18.4,0,33.4,15,33.4,33.4s-15,33.4-33.4,33.4S4.8,56.7,4.8,38.3S19.8,4.8,38.3,4.8 M38.3,2.8
C18.7,2.8,2.8,18.7,2.8,38.3s15.9,35.4,35.4,35.4s35.4-15.9,35.4-35.4S57.8,2.8,38.3,2.8L38.3,2.8z"/>
<path class="st8" d="M38.3,4.8c18.4,0,33.4,15,33.4,33.4s-15,33.4-33.4,33.4S4.8,56.7,4.8,38.3S19.8,4.8,38.3,4.8 M38.3,2.8
C18.7,2.8,2.8,18.7,2.8,38.3s15.9,35.4,35.4,35.4s35.4-15.9,35.4-35.4S57.8,2.8,38.3,2.8L38.3,2.8z"/>
<g class="st5">
<path class="st9" d="M35.2,43.3c-1.5,1-9.1,3.6-14.7-1.1c-4-3.3-4.4-8.7-3.6-24.9c9.5-0.9,17.4,0.9,22,5c4.1,3.6,3.9,8.6,4.3,11.2
C43.6,36.5,39.5,40.4,35.2,43.3z"/>
<path class="st2" d="M44.8,41.6c9.7,6,18.3-7.2,20.2-15.9c-5.5-3.6-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6"/>
<path class="st3" d="M44.8,41.6c9.7,6,18.3-7.2,20.2-15.9c-5.5-3.6-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6z"/>
<path class="st2" d="M44.8,41.6C57.2,51.9,63,36.7,64.9,25.7c-8.2-3.9-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6"/>
<path class="st9" d="M44.8,41.6C57.2,51.9,63,36.7,64.9,25.7c-8.2-3.9-13-2.3-17.7,0.6C43.8,28.5,39.2,35,44.8,41.6z"/>
<path class="st10" d="M22.7,22.6c0,0,14.8,6,11.3,43.2c0,0,12.4-31.6,24-36.1"/>
</g>
<rect x="21.1" y="47.3" class="st11" width="32.6" height="8.1"/>
<g class="st5">
<path class="st12" d="M28.1,53.8h-1l-1.6-5h1l1.2,3.8l1.2-3.8h0.9L28.1,53.8z"/>
<path class="st12" d="M30.8,53.8v-5h3.5v0.8h-2.6v1.2H34v0.8h-2.3V53h2.6v0.8H30.8z"/>
<path class="st12" d="M38.9,53.8l-0.1-0.5c-0.1,0.3-0.6,0.6-1.2,0.6c-0.6,0-1.1-0.1-1.5-0.6c-0.5-0.5-0.6-1.2-0.6-2s0.1-1.5,0.6-2
c0.4-0.4,0.9-0.6,1.5-0.6c0.6,0,1.1,0.2,1.5,0.6c0.2,0.3,0.4,0.6,0.5,1h-0.9c0-0.2-0.1-0.3-0.2-0.5c-0.2-0.2-0.4-0.3-0.8-0.3
c-0.3,0-0.6,0.1-0.8,0.3c-0.3,0.4-0.4,1-0.4,1.4s0,1.1,0.4,1.5c0.2,0.2,0.5,0.3,0.8,0.3c0.3,0,0.6-0.1,0.7-0.3
c0.3-0.3,0.3-0.6,0.3-1h-1.2v-0.8h2.1v2.7H38.9z"/>
<path class="st12" d="M44,53.8l-0.3-1h-2l-0.3,1h-0.9l1.7-5h1l1.7,5H44z M42.7,50L42,52.1h1.4L42.7,50z"/>
<path class="st12" d="M49.1,53.8l-2.2-3.4v3.4H46v-5h1l2.1,3.4v-3.4H50v5H49.1z"/>
</g>
</g>
</svg>
</div>
</html>
why not simply remove the style part inside the SVG ?
(and create your own css [in the html HEAD] with the colors you want)
other just use css !impotant in your css
html { background-color: #eeeeee; }
.icon{
height: 6rem;
width: 6rem;
}
svg { fill:red; }
/* add: */
.st1 { stroke:blue !important; }
path { stroke:orange !important; }
SVG is a regular HTML element. Therefore it takes background-color: white or transparent instead of fill to stylize its background.
I have SVG and what I am doing is I have to change the color of the SVG using css. I tried below code but it's only changing the background color I also want to change the text color.
This is my actual SVG.
My expected output.
I am getting the output.
Is it possible?
.mylogo2 {
fill: yellow;
color: red
}
<div class="mylogo2">
<svg xmlns="http://www.w3.org/2000/svg" width="187.684" height="58.885" viewBox="0 0 187.684 58.885">
<g id="Sample_Logo" data-name="Sample Logo" transform="translate(-475 -511)">
<path id="Path_1" data-name="Path 1" d="M0,19.038,187.684,0V39.848L0,58.885Z" transform="translate(475 511)"/>
<path id="Path_2" data-name="Path 2" d="M6.888-8.456-.56-19.824H4.872l4.2,7.42,4.452-7.42H18.7L11.256-8.456V0H6.888ZM19.1-9.912a11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29A9.807,9.807,0,0,1,25.508-19.6a12.213,12.213,0,0,1,4.284-.728,12.213,12.213,0,0,1,4.284.728,9.807,9.807,0,0,1,3.388,2.086,9.457,9.457,0,0,1,2.226,3.29,11.2,11.2,0,0,1,.8,4.312,11.2,11.2,0,0,1-.8,4.312,9.457,9.457,0,0,1-2.226,3.29A9.807,9.807,0,0,1,34.076-.224,12.213,12.213,0,0,1,29.792.5a12.213,12.213,0,0,1-4.284-.728A9.807,9.807,0,0,1,22.12-2.31,9.457,9.457,0,0,1,19.894-5.6,11.2,11.2,0,0,1,19.1-9.912Zm4.536,0a7.271,7.271,0,0,0,.434,2.562,5.868,5.868,0,0,0,1.246,2.016A5.687,5.687,0,0,0,27.258-4a6.488,6.488,0,0,0,2.534.476A6.488,6.488,0,0,0,32.326-4a5.687,5.687,0,0,0,1.946-1.33A5.868,5.868,0,0,0,35.518-7.35a7.271,7.271,0,0,0,.434-2.562,7.3,7.3,0,0,0-.434-2.548,5.842,5.842,0,0,0-1.246-2.03,5.687,5.687,0,0,0-1.946-1.33,6.488,6.488,0,0,0-2.534-.476,6.488,6.488,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03A7.3,7.3,0,0,0,23.632-9.912Zm36.54,2.268A9.561,9.561,0,0,1,59.64-4.4,7.147,7.147,0,0,1,58.058-1.82,7.247,7.247,0,0,1,55.44-.112,9.83,9.83,0,0,1,51.828.5a9.914,9.914,0,0,1-3.64-.616A7.247,7.247,0,0,1,45.57-1.82,7.147,7.147,0,0,1,43.988-4.4a9.561,9.561,0,0,1-.532-3.248v-12.18h4.368V-7.812A4.827,4.827,0,0,0,48.118-6.1a4.081,4.081,0,0,0,.826,1.358,3.751,3.751,0,0,0,1.274.9,4,4,0,0,0,1.61.322,3.9,3.9,0,0,0,1.6-.322,3.787,3.787,0,0,0,1.26-.9A4.081,4.081,0,0,0,55.51-6.1,4.827,4.827,0,0,0,55.8-7.812V-19.824h4.368ZM64.2-19.824h7.672a13.537,13.537,0,0,1,2.87.294,6.809,6.809,0,0,1,2.38.98A4.883,4.883,0,0,1,78.75-16.7a6.258,6.258,0,0,1,.6,2.9,5.818,5.818,0,0,1-1.092,3.57,4.916,4.916,0,0,1-3.192,1.862L80.108,0H74.872L70.728-7.924H68.572V0H64.2Zm4.368,8.2h2.576q.588,0,1.246-.042a3.9,3.9,0,0,0,1.19-.252,2.058,2.058,0,0,0,.882-.658,2,2,0,0,0,.35-1.26,2.092,2.092,0,0,0-.308-1.2,2.053,2.053,0,0,0-.784-.686,3.478,3.478,0,0,0-1.092-.322,8.908,8.908,0,0,0-1.2-.084H68.572Zm22.232-8.2h4.368V-4.032h8.092V0H90.8Zm13.8,9.912a11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29A9.807,9.807,0,0,1,111.02-19.6a12.213,12.213,0,0,1,4.284-.728,12.213,12.213,0,0,1,4.284.728,9.807,9.807,0,0,1,3.388,2.086,9.457,9.457,0,0,1,2.226,3.29,11.2,11.2,0,0,1,.8,4.312,11.2,11.2,0,0,1-.8,4.312,9.457,9.457,0,0,1-2.226,3.29,9.807,9.807,0,0,1-3.388,2.086A12.213,12.213,0,0,1,115.3.5a12.213,12.213,0,0,1-4.284-.728,9.807,9.807,0,0,1-3.388-2.086,9.457,9.457,0,0,1-2.226-3.29A11.2,11.2,0,0,1,104.608-9.912Zm4.536,0a7.271,7.271,0,0,0,.434,2.562,5.868,5.868,0,0,0,1.246,2.016A5.687,5.687,0,0,0,112.77-4a6.488,6.488,0,0,0,2.534.476A6.488,6.488,0,0,0,117.838-4a5.687,5.687,0,0,0,1.946-1.33A5.868,5.868,0,0,0,121.03-7.35a7.271,7.271,0,0,0,.434-2.562,7.3,7.3,0,0,0-.434-2.548,5.842,5.842,0,0,0-1.246-2.03,5.687,5.687,0,0,0-1.946-1.33A6.488,6.488,0,0,0,115.3-16.3a6.488,6.488,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03A7.3,7.3,0,0,0,109.144-9.912ZM146.916-1.4A15.812,15.812,0,0,1,142.884.056,20.476,20.476,0,0,1,138.6.5a12.213,12.213,0,0,1-4.284-.728,9.807,9.807,0,0,1-3.388-2.086A9.457,9.457,0,0,1,128.7-5.6a11.2,11.2,0,0,1-.8-4.312,11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29,9.806,9.806,0,0,1,3.388-2.086,12.213,12.213,0,0,1,4.284-.728,15.855,15.855,0,0,1,4.382.574A8.58,8.58,0,0,1,146.5-17.78l-3.08,3.36a6.137,6.137,0,0,0-2.016-1.4,7.184,7.184,0,0,0-2.8-.476,6.487,6.487,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03,7.3,7.3,0,0,0-.434,2.548,7.271,7.271,0,0,0,.434,2.562,5.868,5.868,0,0,0,1.246,2.016A5.687,5.687,0,0,0,136.066-4a6.488,6.488,0,0,0,2.534.476,8.349,8.349,0,0,0,2.464-.322,9.3,9.3,0,0,0,1.652-.658v-3.22H139.16V-11.76h7.756Zm2.772-8.512a11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29A9.807,9.807,0,0,1,156.1-19.6a12.213,12.213,0,0,1,4.284-.728,12.213,12.213,0,0,1,4.284.728,9.807,9.807,0,0,1,3.388,2.086,9.457,9.457,0,0,1,2.226,3.29,11.2,11.2,0,0,1,.8,4.312,11.2,11.2,0,0,1-.8,4.312,9.457,9.457,0,0,1-2.226,3.29,9.807,9.807,0,0,1-3.388,2.086A12.213,12.213,0,0,1,160.384.5,12.213,12.213,0,0,1,156.1-.224a9.807,9.807,0,0,1-3.388-2.086,9.457,9.457,0,0,1-2.226-3.29A11.2,11.2,0,0,1,149.688-9.912Zm4.536,0a7.271,7.271,0,0,0,.434,2.562A5.868,5.868,0,0,0,155.9-5.334,5.687,5.687,0,0,0,157.85-4a6.488,6.488,0,0,0,2.534.476A6.488,6.488,0,0,0,162.918-4a5.687,5.687,0,0,0,1.946-1.33A5.868,5.868,0,0,0,166.11-7.35a7.271,7.271,0,0,0,.434-2.562,7.3,7.3,0,0,0-.434-2.548,5.842,5.842,0,0,0-1.246-2.03,5.687,5.687,0,0,0-1.946-1.33,6.488,6.488,0,0,0-2.534-.476,6.487,6.487,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03A7.3,7.3,0,0,0,154.224-9.912Z" transform="matrix(0.995, -0.105, 0.105, 0.995, 484.921, 558.826)" fill="#fff"/>
</g>
</svg>
</div>
You need to change the fill of the second path:
.mylogo2 {
fill: yellow;
}
#Path_2 {
fill: red;
}
<div class="mylogo2">
<svg xmlns="http://www.w3.org/2000/svg" width="187.684" height="58.885" viewBox="0 0 187.684 58.885">
<g id="Sample_Logo" data-name="Sample Logo" transform="translate(-475 -511)">
<path id="Path_1" data-name="Path 1" d="M0,19.038,187.684,0V39.848L0,58.885Z" transform="translate(475 511)"/>
<path id="Path_2" data-name="Path 2" d="M6.888-8.456-.56-19.824H4.872l4.2,7.42,4.452-7.42H18.7L11.256-8.456V0H6.888ZM19.1-9.912a11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29A9.807,9.807,0,0,1,25.508-19.6a12.213,12.213,0,0,1,4.284-.728,12.213,12.213,0,0,1,4.284.728,9.807,9.807,0,0,1,3.388,2.086,9.457,9.457,0,0,1,2.226,3.29,11.2,11.2,0,0,1,.8,4.312,11.2,11.2,0,0,1-.8,4.312,9.457,9.457,0,0,1-2.226,3.29A9.807,9.807,0,0,1,34.076-.224,12.213,12.213,0,0,1,29.792.5a12.213,12.213,0,0,1-4.284-.728A9.807,9.807,0,0,1,22.12-2.31,9.457,9.457,0,0,1,19.894-5.6,11.2,11.2,0,0,1,19.1-9.912Zm4.536,0a7.271,7.271,0,0,0,.434,2.562,5.868,5.868,0,0,0,1.246,2.016A5.687,5.687,0,0,0,27.258-4a6.488,6.488,0,0,0,2.534.476A6.488,6.488,0,0,0,32.326-4a5.687,5.687,0,0,0,1.946-1.33A5.868,5.868,0,0,0,35.518-7.35a7.271,7.271,0,0,0,.434-2.562,7.3,7.3,0,0,0-.434-2.548,5.842,5.842,0,0,0-1.246-2.03,5.687,5.687,0,0,0-1.946-1.33,6.488,6.488,0,0,0-2.534-.476,6.488,6.488,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03A7.3,7.3,0,0,0,23.632-9.912Zm36.54,2.268A9.561,9.561,0,0,1,59.64-4.4,7.147,7.147,0,0,1,58.058-1.82,7.247,7.247,0,0,1,55.44-.112,9.83,9.83,0,0,1,51.828.5a9.914,9.914,0,0,1-3.64-.616A7.247,7.247,0,0,1,45.57-1.82,7.147,7.147,0,0,1,43.988-4.4a9.561,9.561,0,0,1-.532-3.248v-12.18h4.368V-7.812A4.827,4.827,0,0,0,48.118-6.1a4.081,4.081,0,0,0,.826,1.358,3.751,3.751,0,0,0,1.274.9,4,4,0,0,0,1.61.322,3.9,3.9,0,0,0,1.6-.322,3.787,3.787,0,0,0,1.26-.9A4.081,4.081,0,0,0,55.51-6.1,4.827,4.827,0,0,0,55.8-7.812V-19.824h4.368ZM64.2-19.824h7.672a13.537,13.537,0,0,1,2.87.294,6.809,6.809,0,0,1,2.38.98A4.883,4.883,0,0,1,78.75-16.7a6.258,6.258,0,0,1,.6,2.9,5.818,5.818,0,0,1-1.092,3.57,4.916,4.916,0,0,1-3.192,1.862L80.108,0H74.872L70.728-7.924H68.572V0H64.2Zm4.368,8.2h2.576q.588,0,1.246-.042a3.9,3.9,0,0,0,1.19-.252,2.058,2.058,0,0,0,.882-.658,2,2,0,0,0,.35-1.26,2.092,2.092,0,0,0-.308-1.2,2.053,2.053,0,0,0-.784-.686,3.478,3.478,0,0,0-1.092-.322,8.908,8.908,0,0,0-1.2-.084H68.572Zm22.232-8.2h4.368V-4.032h8.092V0H90.8Zm13.8,9.912a11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29A9.807,9.807,0,0,1,111.02-19.6a12.213,12.213,0,0,1,4.284-.728,12.213,12.213,0,0,1,4.284.728,9.807,9.807,0,0,1,3.388,2.086,9.457,9.457,0,0,1,2.226,3.29,11.2,11.2,0,0,1,.8,4.312,11.2,11.2,0,0,1-.8,4.312,9.457,9.457,0,0,1-2.226,3.29,9.807,9.807,0,0,1-3.388,2.086A12.213,12.213,0,0,1,115.3.5a12.213,12.213,0,0,1-4.284-.728,9.807,9.807,0,0,1-3.388-2.086,9.457,9.457,0,0,1-2.226-3.29A11.2,11.2,0,0,1,104.608-9.912Zm4.536,0a7.271,7.271,0,0,0,.434,2.562,5.868,5.868,0,0,0,1.246,2.016A5.687,5.687,0,0,0,112.77-4a6.488,6.488,0,0,0,2.534.476A6.488,6.488,0,0,0,117.838-4a5.687,5.687,0,0,0,1.946-1.33A5.868,5.868,0,0,0,121.03-7.35a7.271,7.271,0,0,0,.434-2.562,7.3,7.3,0,0,0-.434-2.548,5.842,5.842,0,0,0-1.246-2.03,5.687,5.687,0,0,0-1.946-1.33A6.488,6.488,0,0,0,115.3-16.3a6.488,6.488,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03A7.3,7.3,0,0,0,109.144-9.912ZM146.916-1.4A15.812,15.812,0,0,1,142.884.056,20.476,20.476,0,0,1,138.6.5a12.213,12.213,0,0,1-4.284-.728,9.807,9.807,0,0,1-3.388-2.086A9.457,9.457,0,0,1,128.7-5.6a11.2,11.2,0,0,1-.8-4.312,11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29,9.806,9.806,0,0,1,3.388-2.086,12.213,12.213,0,0,1,4.284-.728,15.855,15.855,0,0,1,4.382.574A8.58,8.58,0,0,1,146.5-17.78l-3.08,3.36a6.137,6.137,0,0,0-2.016-1.4,7.184,7.184,0,0,0-2.8-.476,6.487,6.487,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03,7.3,7.3,0,0,0-.434,2.548,7.271,7.271,0,0,0,.434,2.562,5.868,5.868,0,0,0,1.246,2.016A5.687,5.687,0,0,0,136.066-4a6.488,6.488,0,0,0,2.534.476,8.349,8.349,0,0,0,2.464-.322,9.3,9.3,0,0,0,1.652-.658v-3.22H139.16V-11.76h7.756Zm2.772-8.512a11.2,11.2,0,0,1,.8-4.312,9.457,9.457,0,0,1,2.226-3.29A9.807,9.807,0,0,1,156.1-19.6a12.213,12.213,0,0,1,4.284-.728,12.213,12.213,0,0,1,4.284.728,9.807,9.807,0,0,1,3.388,2.086,9.457,9.457,0,0,1,2.226,3.29,11.2,11.2,0,0,1,.8,4.312,11.2,11.2,0,0,1-.8,4.312,9.457,9.457,0,0,1-2.226,3.29,9.807,9.807,0,0,1-3.388,2.086A12.213,12.213,0,0,1,160.384.5,12.213,12.213,0,0,1,156.1-.224a9.807,9.807,0,0,1-3.388-2.086,9.457,9.457,0,0,1-2.226-3.29A11.2,11.2,0,0,1,149.688-9.912Zm4.536,0a7.271,7.271,0,0,0,.434,2.562A5.868,5.868,0,0,0,155.9-5.334,5.687,5.687,0,0,0,157.85-4a6.488,6.488,0,0,0,2.534.476A6.488,6.488,0,0,0,162.918-4a5.687,5.687,0,0,0,1.946-1.33A5.868,5.868,0,0,0,166.11-7.35a7.271,7.271,0,0,0,.434-2.562,7.3,7.3,0,0,0-.434-2.548,5.842,5.842,0,0,0-1.246-2.03,5.687,5.687,0,0,0-1.946-1.33,6.488,6.488,0,0,0-2.534-.476,6.487,6.487,0,0,0-2.534.476,5.687,5.687,0,0,0-1.946,1.33,5.842,5.842,0,0,0-1.246,2.03A7.3,7.3,0,0,0,154.224-9.912Z" transform="matrix(0.995, -0.105, 0.105, 0.995, 484.921, 558.826)" fill="#fff"/>
</g>
</svg>
</div>
Is it possible to style differently a same SVG symbol with 2 distinct CSS classes. Like in this jsfiddle
.shape-55 {
width: 55px;
height: 55px;
}
/* Want to color only the first path in red */
.shape-style-1 path:nth-of-type(1) {
fill: red;
}
/* Want to color only the first path in blue */
.shape-style-2 path:nth-of-type(1) {
fill: blue;
}
<!-- SVG Spritesheets-->
<svg class="shape" style="display:none;">
<symbol viewBox="0 0 64 64" id="shape-1">
<title>sw_av_a_tkn-cscd</title>
<g>
<g>
<path d="M22.541,0C10.511,0,0.723,4.298,0.723,9.581v4.455c0,5.283,9.788,9.581,21.817,9.581c12.032,0,21.819-4.298,21.819-9.581
V9.581C44.359,4.298,34.572,0,22.541,0z M40.568,14.969v3.733c-2.49,1.708-6.309,3.034-10.837,3.726v-3.804
C34.17,17.941,37.963,16.646,40.568,14.969z M7.197,3.443c1.56,0.624,2.804,1.122,3.78,1.513c1.959-0.907,4.483-1.582,7.34-1.925
c-0.348-0.535-0.787-1.213-1.332-2.061c1.771-0.204,3.635-0.315,5.556-0.315c1.926,0,3.792,0.112,5.569,0.318
c-0.548,0.847-0.984,1.522-1.329,2.058c2.851,0.343,5.381,1.018,7.34,1.925c0.973-0.391,2.215-0.888,3.771-1.508
c3.268,1.453,5.387,3.368,5.748,5.483c-2.227,0.07-3.982,0.123-5.357,0.167c0.025,0.158,0.043,0.318,0.043,0.482
c0,1.35-0.918,2.608-2.498,3.665c1.137,0.313,2.582,0.713,4.414,1.219c-2.543,1.629-6.314,2.89-10.756,3.542
c-0.682-0.83-1.229-1.495-1.661-2.02c-1.649,0.252-3.422,0.388-5.271,0.388c0,0-0.003,0-0.006,0c-1.235,0-0.006,0.66-0.006,0
c0,0,0,0-0.002,0c-1.849,0-3.621-0.136-5.271-0.388c-0.432,0.524-0.979,1.19-1.664,2.021c-4.448-0.653-8.223-1.913-10.765-3.544
c1.828-0.506,3.273-0.905,4.41-1.219c-1.58-1.057-2.495-2.315-2.495-3.665c0-0.164,0.018-0.324,0.041-0.482
C5.424,9.055,3.672,9.002,1.44,8.932C1.801,6.814,3.923,4.899,7.197,3.443z M4.512,14.969c2.611,1.679,6.406,2.975,10.854,3.656
v3.806c-4.541-0.691-8.359-2.019-10.854-3.729V14.969z"></path>
<path d="M22.541,13.296c4.596,0,8.199-1.633,8.199-3.715c0-2.084-3.604-3.718-8.199-3.718c-4.597,0-8.197,1.634-8.197,3.718
C14.343,11.663,17.944,13.296,22.541,13.296z M22.541,6.521c4.089,0,7.54,1.4,7.54,3.06c0,1.658-3.451,3.059-7.54,3.059
c-4.087,0-7.541-1.4-7.541-3.059C15,7.922,18.454,6.521,22.541,6.521z"></path>
</g>
<path d="M25.038,34.037c-0.81,0.059-1.638,0.094-2.483,0.094c0,0-0.003,0-0.006,0c0,0-0.002,0-0.006,0c0,0,0,0-0.002,0
c-1.849,0-3.621-0.141-5.271-0.391c-0.432,0.524-0.979,1.191-1.664,2.022c-4.448-0.653-8.223-1.912-10.765-3.546
c1.288-0.355,2.376-0.655,3.312-0.912c-3.259-1.173-5.81-2.753-7.378-4.609c-0.028,0.211-0.052,0.424-0.052,0.64v4.456
c0,5.266,9.721,9.548,21.694,9.58C22.864,38.741,23.758,36.27,25.038,34.037z M15.367,40.185c-4.541-0.69-8.359-2.021-10.854-3.729
v-3.733c2.611,1.679,6.406,2.976,10.854,3.658V40.185z"></path>
<path d="M22.083,45.084c0-0.699,0.041-1.388,0.104-2.069c-1.72-0.018-3.375-0.143-4.917-0.376c-0.432,0.524-0.979,1.189-1.664,2.02
c-4.448-0.652-8.223-1.912-10.765-3.544c1.288-0.355,2.376-0.659,3.312-0.915c-3.259-1.172-5.81-2.749-7.378-4.605
c-0.028,0.21-0.052,0.426-0.052,0.639v4.456c0,5.281,9.788,9.578,21.817,9.578c0.061,0,0.116-0.003,0.175-0.003
C22.316,48.6,22.083,46.868,22.083,45.084z M15.367,49.08c-4.541-0.69-8.359-2.017-10.854-3.728v-3.731
c2.611,1.679,6.406,2.974,10.854,3.655V49.08z"></path>
<path d="M23.161,51.904c-0.204,0.003-0.402,0.023-0.606,0.023c0,0-0.003,0-0.006,0c0,0-0.002,0-0.006,0c0,0,0,0-0.002,0
c-1.849,0-3.621-0.14-5.271-0.391c-0.432,0.524-0.979,1.189-1.664,2.023c-4.448-0.653-8.223-1.915-10.765-3.548
c1.288-0.355,2.376-0.655,3.312-0.912c-3.259-1.172-5.81-2.752-7.378-4.611c-0.028,0.213-0.052,0.426-0.052,0.642v4.456
c0,5.282,9.788,9.581,21.817,9.581c1.519,0,2.999-0.069,4.427-0.198C25.3,56.883,23.998,54.499,23.161,51.904z M15.367,57.979
c-4.541-0.691-8.359-2.018-10.854-3.726v-3.736c2.611,1.679,6.406,2.976,10.854,3.657V57.979z"></path>
<g>
<path d="M44.359,22.805v-4.37c0-0.213-0.02-0.428-0.055-0.639c-1.568,1.858-4.119,3.437-7.375,4.608
c0.863,0.237,1.877,0.518,3.043,0.84C41.393,22.958,42.859,22.805,44.359,22.805z"></path>
<path d="M26.123,32.331c1.037-1.479,2.25-2.82,3.608-4.007v-0.846c0.454-0.069,0.897-0.151,1.341-0.232
c0.432-0.322,0.868-0.633,1.323-0.923c-0.933,0.207-1.9,0.391-2.909,0.539c-0.682-0.831-1.229-1.495-1.661-2.02
c-1.649,0.249-3.422,0.388-5.271,0.388c0,0-0.003,0-0.006,0c0,0-0.002,0-0.006,0c0,0,0,0-0.002,0
c-1.849,0-3.621-0.139-5.271-0.388c-0.432,0.524-0.979,1.188-1.664,2.021c-4.448-0.653-8.223-1.914-10.765-3.546
c1.288-0.355,2.376-0.657,3.312-0.914c-3.259-1.172-5.81-2.75-7.378-4.608c-0.028,0.211-0.052,0.426-0.052,0.639v4.456
c0,5.283,9.788,9.58,21.817,9.58C23.761,32.471,24.954,32.417,26.123,32.331z M15.367,31.285
c-4.541-0.693-8.359-2.018-10.854-3.728v-3.733c2.611,1.679,6.406,2.974,10.854,3.656V31.285z"></path>
</g>
<path d="M44.359,26.166c-10.445,0-18.914,8.469-18.914,18.918C25.446,55.53,33.914,64,44.359,64
c10.451,0,18.918-8.47,18.918-18.916C63.277,34.635,54.811,26.166,44.359,26.166z M53.428,46.976c0,0.49-0.402,0.889-0.891,0.889
h-5.393v5.393c0,0.49-0.4,0.893-0.891,0.893h-3.789c-0.486,0-0.889-0.402-0.889-0.893v-5.393h-5.393
c-0.488,0-0.889-0.398-0.889-0.889v-3.786c0-0.49,0.4-0.892,0.889-0.892h5.393v-5.393c0-0.489,0.402-0.886,0.889-0.886h3.789
c0.49,0,0.891,0.396,0.891,0.886v5.393h5.393c0.488,0,0.891,0.401,0.891,0.892V46.976z"></path>
</g>
</symbol>
</svg>
<div>
<svg class="shape-55 shape-style-1">
<use xlink:href="#shape-1"></use>
</svg>
</div>
<div>
<svg class="shape-55 shape-style-2">
<use xlink:href="#shape-1"></use>
</svg>
</div>
I need to color the first "path" in red when using CSS class shape-style-1 and in blue when using shape-style-2.
Thank you.
You can style the parent div's colors, and use fill: currentColor to use that color for the appropriate SVG element.
So this CSS:
div > svg {
width: 55px;
height: 55px;
}
svg g g > path:nth-of-type(1) {
fill: currentColor;
}
div:nth-of-type(even) {
color: red;
}
div:nth-of-type(odd) {
color: blue;
}
… used with this HTML:
<div><svg><use xlink:href="#shape-1"></use></svg></div>
<div><svg><use xlink:href="#shape-1"></use></svg></div>
<div><svg><use xlink:href="#shape-1"></use></svg></div>
<div><svg><use xlink:href="#shape-1"></use></svg></div>
… will look like this:
Fiddle
You can achieve what you want, but without CSS.
See this fiddle: http://jsfiddle.net/41e0f7z5/2/
The trick is that you can set a fill attribute to the <use> element. Then, your symbol is composed of a path and a group owning all the other pathes. This group has a fillattribute set to black. But, because the firt path has no fillattribute, it will inherit from the <use> one.
<svg class="shape" style="display:none;">
<symbol viewBox="0 0 64 64" id="shape-1">
<path d="..."/>
<g fill="black">
<path d="..." />
<path d="..." />
<path d="..." />
...
</g>
</symbol>
</svg>
<div>
<svg class="shape-55">
<use xlink:href="#shape-1" fill="red"></use>
</svg>
</div>
<div>
<svg class="shape-55">
<use xlink:href="#shape-1" fill="blue"></use>
</svg>
</div>
Something like this?
.shape-55 {
width: 55px;
height: 55px;
}
<body>
<!-- SVG Spritesheets-->
<svg class="shape" style="display:none;">
<symbol viewBox="0 0 64 64" id="shape-1">
<title>sw_av_a_tkn-cscd</title>
<path d="M22.541,0C10.511,0,0.723,4.298,0.723,9.581v4.455c0,5.283,9.788,9.581,21.817,9.581c12.032,0,21.819-4.298,21.819-9.581
V9.581C44.359,4.298,34.572,0,22.541,0z M40.568,14.969v3.733c-2.49,1.708-6.309,3.034-10.837,3.726v-3.804
C34.17,17.941,37.963,16.646,40.568,14.969z M7.197,3.443c1.56,0.624,2.804,1.122,3.78,1.513c1.959-0.907,4.483-1.582,7.34-1.925
c-0.348-0.535-0.787-1.213-1.332-2.061c1.771-0.204,3.635-0.315,5.556-0.315c1.926,0,3.792,0.112,5.569,0.318
c-0.548,0.847-0.984,1.522-1.329,2.058c2.851,0.343,5.381,1.018,7.34,1.925c0.973-0.391,2.215-0.888,3.771-1.508
c3.268,1.453,5.387,3.368,5.748,5.483c-2.227,0.07-3.982,0.123-5.357,0.167c0.025,0.158,0.043,0.318,0.043,0.482
c0,1.35-0.918,2.608-2.498,3.665c1.137,0.313,2.582,0.713,4.414,1.219c-2.543,1.629-6.314,2.89-10.756,3.542
c-0.682-0.83-1.229-1.495-1.661-2.02c-1.649,0.252-3.422,0.388-5.271,0.388c0,0-0.003,0-0.006,0c-1.235,0-0.006,0.66-0.006,0
c0,0,0,0-0.002,0c-1.849,0-3.621-0.136-5.271-0.388c-0.432,0.524-0.979,1.19-1.664,2.021c-4.448-0.653-8.223-1.913-10.765-3.544
c1.828-0.506,3.273-0.905,4.41-1.219c-1.58-1.057-2.495-2.315-2.495-3.665c0-0.164,0.018-0.324,0.041-0.482
C5.424,9.055,3.672,9.002,1.44,8.932C1.801,6.814,3.923,4.899,7.197,3.443z M4.512,14.969c2.611,1.679,6.406,2.975,10.854,3.656
v3.806c-4.541-0.691-8.359-2.019-10.854-3.729V14.969z"></path>
<g fill="black">
<path d="M22.541,13.296c4.596,0,8.199-1.633,8.199-3.715c0-2.084-3.604-3.718-8.199-3.718c-4.597,0-8.197,1.634-8.197,3.718
C14.343,11.663,17.944,13.296,22.541,13.296z M22.541,6.521c4.089,0,7.54,1.4,7.54,3.06c0,1.658-3.451,3.059-7.54,3.059
c-4.087,0-7.541-1.4-7.541-3.059C15,7.922,18.454,6.521,22.541,6.521z"></path>
<path d="M25.038,34.037c-0.81,0.059-1.638,0.094-2.483,0.094c0,0-0.003,0-0.006,0c0,0-0.002,0-0.006,0c0,0,0,0-0.002,0
c-1.849,0-3.621-0.141-5.271-0.391c-0.432,0.524-0.979,1.191-1.664,2.022c-4.448-0.653-8.223-1.912-10.765-3.546
c1.288-0.355,2.376-0.655,3.312-0.912c-3.259-1.173-5.81-2.753-7.378-4.609c-0.028,0.211-0.052,0.424-0.052,0.64v4.456
c0,5.266,9.721,9.548,21.694,9.58C22.864,38.741,23.758,36.27,25.038,34.037z M15.367,40.185c-4.541-0.69-8.359-2.021-10.854-3.729
v-3.733c2.611,1.679,6.406,2.976,10.854,3.658V40.185z"></path>
<path d="M22.083,45.084c0-0.699,0.041-1.388,0.104-2.069c-1.72-0.018-3.375-0.143-4.917-0.376c-0.432,0.524-0.979,1.189-1.664,2.02
c-4.448-0.652-8.223-1.912-10.765-3.544c1.288-0.355,2.376-0.659,3.312-0.915c-3.259-1.172-5.81-2.749-7.378-4.605
c-0.028,0.21-0.052,0.426-0.052,0.639v4.456c0,5.281,9.788,9.578,21.817,9.578c0.061,0,0.116-0.003,0.175-0.003
C22.316,48.6,22.083,46.868,22.083,45.084z M15.367,49.08c-4.541-0.69-8.359-2.017-10.854-3.728v-3.731
c2.611,1.679,6.406,2.974,10.854,3.655V49.08z"></path>
<path d="M23.161,51.904c-0.204,0.003-0.402,0.023-0.606,0.023c0,0-0.003,0-0.006,0c0,0-0.002,0-0.006,0c0,0,0,0-0.002,0
c-1.849,0-3.621-0.14-5.271-0.391c-0.432,0.524-0.979,1.189-1.664,2.023c-4.448-0.653-8.223-1.915-10.765-3.548
c1.288-0.355,2.376-0.655,3.312-0.912c-3.259-1.172-5.81-2.752-7.378-4.611c-0.028,0.213-0.052,0.426-0.052,0.642v4.456
c0,5.282,9.788,9.581,21.817,9.581c1.519,0,2.999-0.069,4.427-0.198C25.3,56.883,23.998,54.499,23.161,51.904z M15.367,57.979
c-4.541-0.691-8.359-2.018-10.854-3.726v-3.736c2.611,1.679,6.406,2.976,10.854,3.657V57.979z"></path>
<path d="M44.359,22.805v-4.37c0-0.213-0.02-0.428-0.055-0.639c-1.568,1.858-4.119,3.437-7.375,4.608
c0.863,0.237,1.877,0.518,3.043,0.84C41.393,22.958,42.859,22.805,44.359,22.805z"></path>
<path d="M26.123,32.331c1.037-1.479,2.25-2.82,3.608-4.007v-0.846c0.454-0.069,0.897-0.151,1.341-0.232
c0.432-0.322,0.868-0.633,1.323-0.923c-0.933,0.207-1.9,0.391-2.909,0.539c-0.682-0.831-1.229-1.495-1.661-2.02
c-1.649,0.249-3.422,0.388-5.271,0.388c0,0-0.003,0-0.006,0c0,0-0.002,0-0.006,0c0,0,0,0-0.002,0
c-1.849,0-3.621-0.139-5.271-0.388c-0.432,0.524-0.979,1.188-1.664,2.021c-4.448-0.653-8.223-1.914-10.765-3.546
c1.288-0.355,2.376-0.657,3.312-0.914c-3.259-1.172-5.81-2.75-7.378-4.608c-0.028,0.211-0.052,0.426-0.052,0.639v4.456
c0,5.283,9.788,9.58,21.817,9.58C23.761,32.471,24.954,32.417,26.123,32.331z M15.367,31.285
c-4.541-0.693-8.359-2.018-10.854-3.728v-3.733c2.611,1.679,6.406,2.974,10.854,3.656V31.285z"></path>
<path d="M44.359,26.166c-10.445,0-18.914,8.469-18.914,18.918C25.446,55.53,33.914,64,44.359,64
c10.451,0,18.918-8.47,18.918-18.916C63.277,34.635,54.811,26.166,44.359,26.166z M53.428,46.976c0,0.49-0.402,0.889-0.891,0.889
h-5.393v5.393c0,0.49-0.4,0.893-0.891,0.893h-3.789c-0.486,0-0.889-0.402-0.889-0.893v-5.393h-5.393
c-0.488,0-0.889-0.398-0.889-0.889v-3.786c0-0.49,0.4-0.892,0.889-0.892h5.393v-5.393c0-0.489,0.402-0.886,0.889-0.886h3.789
c0.49,0,0.891,0.396,0.891,0.886v5.393h5.393c0.488,0,0.891,0.401,0.891,0.892V46.976z"></path>
</g>
</symbol>
</svg>
<div>
<svg class="shape-55 shape-style-1" fill="red">
<use xlink:href="#shape-1"></use>
</svg>
</div>
<div>
<svg class="shape-55 shape-style-2" fill="blue">
<use xlink:href="#shape-1"></use>
</svg>
</div>
</body>