Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style SVG children #79

Closed
bytrangle opened this issue Jan 26, 2023 · 3 comments
Closed

Style SVG children #79

bytrangle opened this issue Jan 26, 2023 · 3 comments
Labels
question Further information is requested

Comments

@bytrangle
Copy link

As I understand, you can only style the top-level <svg> element, the one with data attribute [astro-icon] like below:

<style>
    [astro-icon] {
        color: blue;
        /* OR */
        fill: blue;
    }
</style>

Targeting child of the SVG, like path element won't work:

<style lang="css">
  /* Nothing happens here*/
    [astro-icon] path {
        fill: blue;
    }
</style>

I would like to know if this is the intended behavior of Astro Icon. Is there any plan to allow for styling SVG children?

@stramel
Copy link
Collaborator

stramel commented Mar 15, 2023

Thanks for bringing this up. Can you provide some more details or perhaps an example showing the issue?

We have had a couple discussions about styling children before starting in #49. Let me know if you have a different issue.

@stramel stramel added the question Further information is requested label Mar 15, 2023
@matthacksteiner
Copy link

Sorry to hijacking this conversation - a real world example would be this:

<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 40 40">
    <rect fill="#000" width="38.25" height="38.25" x=".875" y=".875" stroke="#000" stroke-width="1.75" class="rect" rx="4.125" />
    <path fill="#000" d="m21.535 26.773 7.893-6.009v-1.422l-7.893-6.009v5.405H10.37v2.63h11.165v5.405Z" />
</svg>

How can we style only the path with fill="#aaa"?

@stramel
Copy link
Collaborator

stramel commented May 13, 2023

should be the same way as in #49

svg path {
  fill: #aaa;
}

https://stackblitz.com/edit/github-ex6klk-31wfte?file=src/pages/index.astro

Closing as duplicate of #49

@stramel stramel closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants