Replies: 1 comment
-
|
Your workaround is the correct approach - @theme blocks must be top-level (not in @media) because they instruct Tailwind to generate utilities at build time. Define responsive CSS variables in :root with media queries, then reference them in @theme: @theme {
--spacing-card-width: var(--spacing-card-width);
}
@media (width >= 80rem) {
:root {
--spacing-card-width: clamp(15rem, 18.5vw + 1rem, 30rem);
}
}This works because @theme registers the variable with Tailwind at build time, while the actual values are overridden at runtime via CSS cascade. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I attempted to implement responsive @theme changes in Tailwind CSS v4 using @media queries, but discovered that @theme directives don't support dynamic overrides within media queries. Instead, I used standard CSS custom properties defined in :root with proper media query ranges, then referenced those variables inside the @theme block (e.g., --spacing-card-width: var(--spacing-card-width);). This approach leverages Tailwind's theme system while maintaining full responsive control through native CSS cascade rules.
`@import "tailwindcss";
:root {
font-family: "IBM Plex Sans", sans-serif;
}
@theme {
/* custom breakpoints */
--breakpoint-1280w: 80rem;
--breakpoint-1440w: 90rem;
--breakpoint-1920w: 120rem;
--breakpoint-2560w: 160rem;
--breakpoint-3840w: 240rem;
}
/* 1280w < res < 1440w /
@media (width >= 80rem) and (width < 90rem) {
:root {
/ video-card /
/ sizes */
--spacing-card-width: clamp(15rem,18.5vw + 1rem,30rem);
--spacing-card-height: clamp(15rem,25vw + 1rem,30rem);
}
/* 1440w < res < 1920w /
@media (width >= 90rem) and (width < 120rem) {
:root {
/ video-card /
/ sizes */
--spacing-card-width: clamp(15rem,18.5vw + 1rem,30rem);
--spacing-card-height: clamp(15rem,25vw + 1rem,30rem);
}`
Beta Was this translation helpful? Give feedback.
All reactions