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

[css-cascade] defining a layer with an attribute for ease of use with third-party injected style elements #7592

Closed
MSanbira opened this issue Aug 11, 2022 · 3 comments

Comments

@MSanbira
Copy link

After integrating the cascade layers into our existing main app (React), I had some trouble with third-party npm modules that inject their CSS with <style> tags dinamickly.

I needed them to be in the @layer third-party so it would not override the rest of our custom CSS. So I used a workaround by listening to the <header> changes and changing each <style> element's inner text. It worked great but it still feels a bit hacky.

Some time passed and I was thinking that adding an element attribute to define a layer from the outside like:

<header>
  <style layer="third-party">
    div { font-size: 42px; }
  </style>

  <!-- or -->
  
  <style cascade-layer="third-party">
    div { font-size: 42px; }
  </style>

  <!-- ... other styles -->
</header>

I know that it will help me for better integrations, I hope that some of you share similar opinions.
this is the first time trying to contribute to w3c, if some of you think I'm going about it in some wrong way please let me know. I want to start being a part of the CSS bigger picture, thanks.

@hober hober added the css-cascade-4 Current Work label Aug 11, 2022
@ydaniv
Copy link
Contributor

ydaniv commented Aug 14, 2022

Hey @MSanbira, that's probably not a bad idea, and it's already in progress (AFAIK), see here: https://css-tricks.com/css-cascade-layers/#aa-assigning-layers-in-html-with-the-link-tag 😄

@MSanbira
Copy link
Author

@ydaniv thanks for commenting! 😌 I know there is a link tag attribute in progress but I'm talking about the style tag. webpack and other npm add-ons like to add their styles with style elements and not links. would the layer attribute in consideration also apply to style tags? because I didn't see any mention of this.

@SebastianZ
Copy link
Contributor

The discussion for that is actually already happening in #5853.

@MSanbira Maybe you can outline your use case there.

Sebastian

@SebastianZ SebastianZ added css-cascade-5 and removed css-cascade-4 Current Work labels Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants