by tiffanyh · 2y ago · 0 comments
As someone who has been handwriting HTML/CSS for literally 25-years, I'm still shocked dealing with media break points isn't easier.
It easily snowballs into you having 3 different CSS (phone/tablet/desktop).
I wish there was something akin to 'light-dark' (where you can specific a different value conditional on the environment) but would be trigger based on window size.
e.g.
font-size: window-size(1.2em, 1em, 0.8em)
Which would translate to, if the browser window is small (phone), use 1.2em ... if browser window is large (desktop), use 0.8emhttps://developer.mozilla.org/en-US/docs/Web/CSS/color_value...
Edit: Though even simpler than that is the width media query, which I think you might be looking for: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/widt...
I've just found that approach very clunky in practice, hence my comment about it snowballs into effectively having 3 different CSS (phone/tablet/desktop) and wrapped in media width queries.
Though maybe I use it incorrectly.
I'm always open to learning something new :)
Also, some units cascade. So if you set the top-level or parent to a particular size, then child elements inside can inherit (or ignore) the unit. This means at a top level you can set your font-size for each @media width, and then use relative units and it will inherit down. But that only works for very small websites, because it introduces subtle bugs as you incorporate more controls from people not aware of your particular practice.
https://stackoverflow.com/questions/40722882/css-native-vari...
<div className="text-sm lg:text-lg"> Hello World </div>
I don't know how resizing defaults would work well for most cases instead of specifying what you want.
font-size: clamp(3.125rem, 3.464vw + 2.229rem, 5rem);
From their website, this is not easy code to maintain.It’s not obvious how to increase/decrease the font size at a later date.
It generates step size variables and a comment linking back to the web calculator filled with your values.
I suspect its that every new project, you deviate, whether someone implements it differently, or someone else entirely implements it, and now you have to hack your way around the chosen path.
The one insane sounding approach I've seen is to just have a UI for one screen, and another ui for another. You hide one on mobile, the other on desktop.
There's so much nuance too, if you dont specify some meta tag your media breakpoints wont even work, which you'll forget when you start a new project after spending 6 years on an already built project.
text=[1.2em] md:text=[1.0em] lg:text=[0.8em]That should reduce the media query worry to one single breakpoint, no?
text-sm md:text-base lg:text-lg
Mobile: font-size: 0.875rem; /* 14px / line-height: 1.25rem; / 20px /
Tablet: font-size: 1rem; /
16px / line-height: 1.5rem; / 24px /Desktop: font-size: 1.125rem; /
18px / line-height: 1.75rem; / 28px */ <div class="sm:text-lg lg:text-sm" />