-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
🐛 BUG: CSS imported have higher priority than CSS on .astro file #3357
Comments
Thanks for opening an issue! You're right that our specificity is a bit wonky and difficult to control right now. This problem is something we've discussed in the past but never came to a resolution on. I'm tagging this issue to be reviewed and discussed by the core team. Related: we have an open PR to ensure that Astro scoped styles use |
Hi @natemoo-re , I've been using the |
+1 - Global styles imported in components land before TailwindCSS base styles, losing specificity battle in the result. A nasty but quick workaround is to simply make global styles slightly more specific and wrap selectors by e.g. |
really hoping a solution appears 🙏 |
this happens in 1.0 stable as well |
The |
astro@1.3.0
Same results using So using "static stylesheet via “link” tags" skips the normal CSS processing, bundling and optimizations BUT, you could write your globals there and you will have the possibility to overwrite them with |
Please consider revising CSS load order to:
If those are all added to |
Hey everyone, we just pushed at a fix for this that will be released in 1.4.0. Let me clarify the ordering as it's intended so that we're all on the same page. Let's say you have this: ---
import '../styles/base.css';
import '../styles/global.css';
---
<html>
<head>
<link rel="stylesheet" href="/another.css">
<style>
body {
background: limegreen;
}
</style>
</head>
</html> The ordering you should see is: <link rel="stylesheet" href="/another.css">
<link rel="stylesheet" href="/styles/base.css">
<link rel="stylesheet" href="/styles/global.css">
<!-- this is your <style> -->
<link rel="stylesheet" href="/src/pages/index.astro?type=style..."> The change made is that your Here's a couple of things to remember:
I hope that clears things up! There's still likely some issues to address. Code-splitting in particular makes preserving order very hard, so built-order is more likely to not follow the above rules. Please still report anything that you find. |
Thank you, I just tested 1.4.0 and it works as intended! |
What version of
astro
are you using?1.0.0-beta.27
Are you using an SSR adapter? If so, which one?
no
What package manager are you using?
npm
What operating system are you using?
Windows
Describe the Bug
When I import CSS like
import '../styles/style.css';
or CSS contained in other .astro file likeimport Layout from '../layouts/Layout.astro';
This imported CSS as priority over the CSS inside the<style>
on a .astro file.This way, an external CSS rule with the same specificity will overwrite the one on
<style is:global>
And you could say, use scoped
<style>
... but certain elements are not affected by the:global()
oris:global
, like*
,html
orbody
.So if I create a CSS rule for
body
on an external file it would be hard to change it unless I use!important
We should not rely on specificity for this, the internal CSS should always be written at the bottom of the file.
To sum up, the CSS file (asset.xxx.css) from
astro build
and the temporal CSS file fromastro dev
. IMA have the content in the wrong order.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ndeuc4-qbjgyn?file=src%2Fpages%2Findex.astro,src%2Fpages%2Fpage2.astro
Participation
The text was updated successfully, but these errors were encountered: