You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed in this closed feature request, the newly introduced scoped global styles do not work in most cases because of CSS specificity.
Because of CSS specificity if an element has more classes than another then it takes precedence when being rendered. So if in one of my +page.svelte files I want to edit an element to make it work perfectly for that page I will usually add a class to it (in most of my pages I have special cases that need custom styles).
However as you can see my custom styles are being ignored in favour of the global styles from my +layout.svelte file.
I did try using ID's instead of classes to select the element and that does work in some cases, but would not work if I wanted to select the same class name that is called in the +layout.svelte file (without creating a second selector for every element).
Also generally ID's are for javascript and classes for CSS, I have not used them in my design work for a long long time. It would also require an substantial amount of work to change all classes to ID's.
I agree that is how CSS works, orginally I opened a feature request for this, not an issue. The suggested solution is what has this issue.
How I think this feature could work would be if Svelte handled it in the background in a similar way to how it currently appends a .myclass.randomId to each class. If it could do that for all the CSS that it grabs from the +layout.svelte files above it then the experience would be seamless.
Since global is currently for the whole project perhaps a different name would work like:
Describe the bug
As discussed in this closed feature request, the newly introduced scoped global styles do not work in most cases because of CSS specificity.
Because of CSS specificity if an element has more classes than another then it takes precedence when being rendered. So if in one of my +page.svelte files I want to edit an element to make it work perfectly for that page I will usually add a class to it (in most of my pages I have special cases that need custom styles).
However as you can see my custom styles are being ignored in favour of the global styles from my +layout.svelte file.
I did try using ID's instead of classes to select the element and that does work in some cases, but would not work if I wanted to select the same class name that is called in the +layout.svelte file (without creating a second selector for every element).
Also generally ID's are for javascript and classes for CSS, I have not used them in my design work for a long long time. It would also require an substantial amount of work to change all classes to ID's.
Reproduction
Download this repository: https://github.com/Loizzus/SvelteScopedGlobalStylesIssue
npm i
npm run dev
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: