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
Define css variables, do not add to the style attribute of each tag #7328
Comments
I assume we are doing it this way because this avoids |
---
const color = 'red';
---
<div>
1111
<button type="button">button</button>
</div>
<style define:vars={{ color }}>
button {
color: var(--color);
}
</style> build:
|
@J-env Where is it defined to |
@matthewp The outermost element of the component buid: <div style="--color-hash: red;">
1111
<button type="button">button</button>
</div>
<style>
button.astro-hash {
color: var(--color-hash);
}
<style> |
It's an ongoing issue, one that definitely needs reconsideration. I think only setting Arguably, you're doing more work by outputting that style attribute on Let me throw another use-case out there... I have a component for a section to which I'm adding a background image (three, actually, for responsive lazy loading). If I use More generically, if I make a Card component with a And I understand that it's almost antithetical to the whole idea of Astro, but it feels like it simplifies things in an intuitive way. (Full disclosure, I'm still somewhat new to Astro, so maybe I'm just doing things entirely wrong. Only really started using it a couple weeks ago for a project here at work. But I gotta say, I really like it so far.) |
This is definitely the wrong behavior. In addition to ballooning components, it would actually get in the way of trying to intentionally override variables within the component itself. |
What version of
astro
are you using?2.6.1
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm,pnpm
What operating system are you using?
Mac
What browser are you using?
Chrome
Describe the Bug
// css-test.astro
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-sdeict-dc8tm6?file=src%2Fcomponents%2FDefineVars.astro
Participation
The text was updated successfully, but these errors were encountered: