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

construct stylesheet priority #127

Open
mantou132 opened this issue Mar 20, 2020 · 2 comments
Open

construct stylesheet priority #127

mantou132 opened this issue Mar 20, 2020 · 2 comments

Comments

@mantou132
Copy link

mantou132 commented Mar 20, 2020

const sheet = new CSSStyleSheet();
sheet.replaceSync(`
  h1 {
    color: blue;
  }
`);

document.adoptedStyleSheets = [sheet];

document.body.innerHTML = `
  <style>
    h1 {
      color: red;
    }
  </style>
  <h1>title</h1>
`;

construct stylesheet overrides <style>.

but sometimes I don't want to override the style of <style> <link> in the code, I just want to construct stylesheet to work like a browser stylesheet. // case: <gem-frame>

is there a way to determine the priority of constructing stylesheet?

@nordzilla
Copy link
Contributor

This was discussed and resolved here:
#93 (comment)

As of right now, constructed always go after other author sheets.

@mantou132
Copy link
Author

mantou132 commented Oct 13, 2023

use @layer can solve the problem:

const sheet = new CSSStyleSheet();
sheet.replaceSync(`
  @layer { 
    h1 {
      color: blue;
    }
  }
`);

document.adoptedStyleSheets = [sheet];

document.body.innerHTML = `
  <style>
    h1 {
      color: red;
    }
  </style>
  <h1>title</h1>
`;

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

No branches or pull requests

2 participants