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

How to move global styles into scope for emotion ? #1789

Closed
JulienKode opened this issue Mar 6, 2020 · 4 comments
Closed

How to move global styles into scope for emotion ? #1789

JulienKode opened this issue Mar 6, 2020 · 4 comments
Labels

Comments

@JulienKode
Copy link

JulienKode commented Mar 6, 2020

Thank you for this nice library and all effort that you make πŸ‹πŸΌβ€β™€οΈ

I'm currently need to integrate common components of a library into multiples websites. The component Library currently have a Global styles. That they inject in the following way:

  <Global
    styles={`
        div {
          padding: 0;
        }
    `}
  />

I want there "Global styles" only available for the components of this library. They are only on a part of the page.

So I've try this:

const Styles = styled.div`
        div {
          padding: 0;
        }
`;

const Page = () => (
    <Styles>
        <SomeComponentsOfTheLibrary />
    </Styles>
);

But it seems that everything in Styles has the priority. Then if the component has padding: 10px; it will take padding: 0; of Styles

Here is the issue reproduced:

I know It's a css issue but I want to solve it with emotion
I've already saw:

@JulienKode JulienKode changed the title [SUPPORT] - How to move global styles into scope for emotion How to move global styles into scope for emotion Mar 6, 2020
@JulienKode JulienKode changed the title How to move global styles into scope for emotion How to move global styles into scope for emotion ? Mar 6, 2020
@Andarist
Copy link
Member

Andarist commented Mar 7, 2020

Demo which I've posted on Twitter regarding this issue can be found here: https://codesandbox.io/s/upbeat-morning-8rfur

I believe this solves the problem in the best possible way. Emotion styles are just styles, so if you integrate with non-emotion styles you, unfortunately, need to fight specificity wars.

@Andarist Andarist closed this as completed Mar 7, 2020
@JulienKode
Copy link
Author

Thank you again @Andarist 😊

I've update the stack overflow post: https://stackoverflow.com/questions/60567233/how-to-move-global-styles-into-a-scope-for-emotion with your best solution

@Chinomso1995
Copy link

@Andarist what if the children are of a different CSS framework. Like they are based off tailwind and I want them to retain their original styles and not the one from the global styles.

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

No branches or pull requests

3 participants