question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apply class to svg itself

See original GitHub issue

Hi @czeckd, its a really neat plugin!

About the applyCss, it only work if the applied class is specific for using with the svg element. In my case, i have class that’s for general use, for example:

.h-12 {
    height: 3rem;
}

If i use the applyCss like this:

<svg-icon [applyCss]="true" class="h-12" src="assets/images/test.svg"></svg-icon>

It won’t work, because my class don’t apply the styles to the <svg> element. Is there any way to make the class applied to the <svg-icon> be transported to the <svg> tag?

_Originally posted by @filipedtristao in https://github.com/czeckd/angular-svg-icon/issues/58#issuecomment-588521108_

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
czeckdcommented, Apr 9, 2020

@vaindil @MaximSagan - I backed out the change that automatically duplicated the svg-icon class and applied it to the svg. It is in version 9.2.0.

@filipedtristao - You have two options to apply the svg-icon class to the svg in 9.2.0. You can use the new [svgClass] attribute or use the [class] attribute and set applyClass="true" to duplicate the svg-icon class onto the svg.

1reaction
czeckdcommented, Feb 20, 2020

@filipedtristao

To work like you suggest, it will need some code change. For now, you can work around the issue by adding this to your scss:

.h-12 {
    height: 3rem;

    svg {
        height: 3rem;
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding Class to SVG - css - Stack Overflow
You can use CSS styles (whether based on class, id, or some other CSS selector) in SVG. It's a little tricky to mix...
Read more >
class - SVG: Scalable Vector Graphics - MDN Web Docs
Assigns a class name or set of class names to an element. You may assign the same class name or names to any...
Read more >
5 Gotchas You're Gonna Face Getting Inline SVG Into ...
Fortunately, there's a trick we can use to at least get one unique color per instance. If we go in to the SVG...
Read more >
Document Structure — SVG 2
An SVG document fragment can stand by itself as a self-contained file or ... Note the use of XML namespaces to indicate that...
Read more >
Manipulating - SVG.js v3.0
Class Names. addClass(). returns itself. Adds a given css class: element.addClass('pink-flower ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found