Based on the knowledge sources provided, I can explain why the CSS variables are not working as expected in your code. The issue is related to how the is:global directive and define:vars interact in Astro.
According to the Astro documentation on Script & Style Directives, the is:global directive makes the contents of a <style> tag apply globally on the page. However, it's important to note that when you use define:vars, it doesn't automatically imply is:inline.
The define:vars directive is used to pass variables from your component's frontmatter to the <style> tag. However, when combined with is:global, it may not behave as expected.
To solve this issue, you have a couple of options:
- Remove the
is:global directive if you want to keep using define:vars and scope the styles to your component:
<style define:vars={{ skillColor, fontWeight, textCase }}>
h1 {
color: var(--skillColor) !important;
font-size: 4rem;
}
.skill {
color: var(--skillColor);
font-weight: var(--fontWeight);
text-transform: var(--textCase);
}
/* ... rest of your styles ... */
</style>
- If you need global styles, you can define the CSS variables in a separate
<style is:global> tag and then use them in your component:
<style is:global>
:root {
--skillColor: navy;
--fontWeight: bold;
--textCase: uppercase;
}
</style>
<style>
h1 {
color: var(--skillColor) !important;
font-size: 4rem;
}
.skill {
color: var(--skillColor);
font-weight: var(--fontWeight);
text-transform: var(--textCase);
}
/* ... rest of your styles ... */
</style>