-
|
I'm trying to follow the example from the Tailwind v4 docs regarding how to get a CSS value in JS. I specifically want to get a function matchesBreakpoint(breakpoint: string): boolean {
const styles = window.getComputedStyle(document.documentElement);
const property = `--breakpoint-${breakpoint}`;
const size = styles.getPropertyValue(property) || "0px";
return window.matchMedia(`(min-width: ${size}`).matches;
}Unfortunately, the call to I did come across this similar discussion, which calls out using @theme static {
--breakpoint-sm: var(--breakpoint-sm);
--breakpoint-md: var(--breakpoint-md);
--breakpoint-lg: var(--breakpoint-lg);
--breakpoint-xl: var(--breakpoint-xl);
--breakpoint-2xl: var(--breakpoint-2xl);
}...does not work since it just results in CSS warnings like How can I expose these predefined breakpoint values to my JS? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
You'd use @import "tailwindcss" theme(static);This would then mean all CSS variables would be available. Otherwise, to pick out the core breakpoints to be statically output, you could do: @import "tailwindcss";
@theme static {
--breakpoint-sm: 40rem;
--breakpoint-md: 48rem;
--breakpoint-lg: 64rem;
--breakpoint-xl: 80rem;
--breakpoint-2xl: 96rem;
} |
Beta Was this translation helpful? Give feedback.
You'd use
staticto include all Tailwind's default variables like:This would then mean all CSS variables would be available.
Otherwise, to pick out the core breakpoints to be statically output, you could do: