Skip to content

Insert the stylesheet into the SVG instead of the head? #578

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

Closed
mbostock opened this issue Oct 21, 2021 · 1 comment · Fixed by #579
Closed

Insert the stylesheet into the SVG instead of the head? #578

mbostock opened this issue Oct 21, 2021 · 1 comment · Fixed by #579
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

This way, it’ll work out of the box with React and other frameworks, and it’ll work better with Observable’s Download SVG since the stylesheet will be included. Related #248.

@mbostock mbostock added the enhancement New feature or request label Oct 21, 2021
@shancarter
Copy link

shancarter commented Oct 21, 2021

Thinking about this more last night, was wondering if this inheritance was more what I would want? I was worried about the styles leaking out of the plot svg into my surrounding document. (though with namespaced selectors, maybe not a problem)

  <svg>
    <g class="plot" font-family="system-ui, sans-serif" font-size="10">
      <text x=20 y=20>Test</text>
    </g>
  </svg>

so then I could easily do this to override the styles:

<div>
<style>
  .plot {
    font-size: 22px;
  }
</style>
  <svg>
    <g class="plot" font-family="system-ui" font-size="10">
      <text x=20 y=20>Test</text>
    </g>
  </svg>
  
</div>

If the styles were inside the svg, I would have to do this:

<div>
  <style>
      svg .plot {
        font-size: 22px;
      }
    </style>
  <svg>
    <style>
      .plot {
        font-size: 10px;
      }
    </style>
    <g class="plot">
      <text x=20 y=20>Test</text>
    </g>
  </svg>
  
</div>

which is not terrible, but slightly more annoying.

Stepping back a minute too, the reason the text css feels different than the other css in plot/style.css is that they affect the presentation of the content of the svg. The other things in style.css are css styles that only really affect the container. I sort of mostly want a plot chart to act like an image when I'm integrating in into another environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants