Replies: 4 comments 1 reply
-
|
This is because of the CSS specification of media queries and not anything within Tailwind CSS:
So, I could see one reason this was done, to avoid infinite loops: @media (min-width: 100rem) {
:root {
font-size: 20px;
}
}If you had a viewport that was say, |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
Hello! This behavior is actually correct according to CSS specifications, not a Tailwind CSS issue. As @wongjn correctly explained, media queries always use the browser's base font size (typically 16px) regardless of CSS CSS Specification Behavior:
Solution: Use Pixel Values for Breakpoints @import "tailwindcss";
:root {
font-size: 18px; /* Affects element sizing */
}
@theme {
/* Use pixel values for media queries */
--breakpoint-sm: 656px; /* 41rem × 16px */
--breakpoint-md: 784px; /* 49rem × 16px */
--breakpoint-lg: 1040px; /* 65rem × 16px */
--breakpoint-xl: 1296px; /* 81rem × 16px */
--breakpoint-2xl: 1552px; /* 97rem × 16px */
/* Container queries can use rem since they're element-relative */
--container-sm: 41rem;
--container-md: 49rem;
--container-lg: 65rem;
--container-xl: 81rem;
--container-2xl: 97rem;
}Alternative: CSS Custom Properties with calc() @import "tailwindcss";
:root {
--base-font-size: 18px;
font-size: var(--base-font-size);
}
@theme {
/* Convert rem to pixels manually */
--breakpoint-sm: calc(41 * 16px);
--breakpoint-md: calc(49 * 16px);
--breakpoint-lg: calc(65 * 16px);
--breakpoint-xl: calc(81 * 16px);
--breakpoint-2xl: calc(97 * 16px);
}Why This Happens:
The solution is to explicitly use pixel values for media query breakpoints while keeping |
Beta Was this translation helpful? Give feedback.
-
I tried this work aroung but it dosn't work. Any idea? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In the Tailwind playground https://play.tailwindcss.com/, I entered this HTML code for testing:
CSS:
All the breakpoints are correctly overridden. In the case of the container, it is calculated correctly by multiplying by 18px, while in the case of the classic breakpoints, it is still multiplied by 16px despite the font-size setting of 18px. If I use other tailwind class like text-sm and so on, it is correctly multiplying by 18px.
Beta Was this translation helpful? Give feedback.
All reactions