Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Svelte importing svg as compoment works weird

I've created this repl to demonstrate this issue. One SVG is just added inline and works ok, the other is imported as a component and doesn't work as intended. What's the difference? How do I get this scenario to work?

like image 585
Georg K. Avatar asked Sep 17 '25 11:09

Georg K.


1 Answers

The problem is the style scoping. Since the SVG is inside another component, the styles of the parent component do not apply, you need to use :global or work with CSS variables:

  .my-stuff-svg-container :global(svg) {
    color: white;
    height: 1rem;
    width: 1rem;
    transition: 0.25s ease;
  }
like image 152
H.B. Avatar answered Sep 19 '25 03:09

H.B.