187 points · by shadeed · 3y ago · 84 comments
That technique of using a style tag to set a CSS var (--horizontal) then using @container tags to shift the UI is really cool.
<div class="c-newspaper__item" style="--horizontal: true;">
<article class="c-card"></article>
</div>
.c-newspaper__item {
container-type: inline-size;
container-name: card;
}
@container card (min-width: 300px) and style(--horizontal: true) {
.c-card {
display: flex;
gap: 1rem;
}
}
Also, as someone who learned CSS in the early 2000s, seeing grid layouts with `grid-template-columns:` etc make life so much easier. Web devs have it easier these days.If you use them, you'll need to show outdated browser warnings for basically all browsers older than September 2022. Your site will be horrifically broken without container query support.
I'm investigating if we want to even do that at my job. That's a pretty steep cost.
They’d also be pretty expensive on the client
<head>
...
<style>
.example {
container-type: inline-size;
}
@container (min-width: 200px) {
h1 {
font-size: 15cqw;
font-family: monospace;
}
}
</style>
</head>
<body>
<div class="example">
<h1>hello world</h1>
</div>
</body>Web dev is way easier now, if all you're trying to do is the same stuff we tried to do in the early 2000s. All the stuff that makes it harder is because we can do some much more now.
As someone who did webdev back in the 2000s and still does it now, I do not agree with this at all. Webdev is easy now. Especially with the development of simpler build systems (esbuild, vite, etc) in the couple of years.
If you want to build something you build back in the 2000s, its so much easier than it was back then.
<div class="c-newspaper__item display-flex gap-1rem">
<article class="c-card"></article>
</div>
.display-flex {
display: flex;
}
.gap-1rem {
gap: 1rem;
}That sounds like using a feature for the sake of using a feature. Couldn't the same be done with a class on the container?
Whilst it works, and the presented code is certainly clean enough, it could be argued that such techniques are not really true modern CSS, something flex based would likely be the true modern way.
See, for example, the approach taken by Every Layout: https://every-layout.dev/layouts/sidebar/
Also, all browsers these days just do a fancy page zoom instead of directly manipulating font size. It's a much better setup than what we had to do in days of yore, e.g. using different units on different properties so that things didn't fall apart on size increase.
This is very not true. Hit Alt V Z T in Firefox, for example. It's even on WebAIM's accessibility checklist (https://webaim.org/resources/evalquickref/#scaling), which makes it important: that list is very selective.
Microsoft Edge on Windows 10 has at least three different kinds of zoom, depending on which input device you use to trigger it. (Multiple types of zoom: good. None of the keyboard / mouse / touchpad bindings doing the same? Bad.)
Sometimes change for the sake of using the latest bleeding edge thing isn't really worth it.
The main goal of this is to explore the potential of modern CSS in building such a layout. I agree that some of the features aren't supported yet, but that will become better over time. The article shed light on things like container queries, fluid sizing.. etc.
• Container queries have less than a year’s support in any browser;
• Style container queries have only an incomplete implementation in Chromium for a month;
• :has() isn’t in Firefox yet and has been in other browsers for a year at most.
That is: you can’t actually depend on these features yet.
If you want to serve content to human people and not just to eyes or wallets then at least be aware that most modern browser share statistics collected with JS don't reflect the reality you'd see in your webserver logs.
I don't think the demographic is realistically relevant.
97.23% of internet users do not care.
If you are arguing to not use Working Draft mechanisms in production environments (and you probably are), yes you have a point. Better safe than sorry, it's called a Working Draft for a reason.
But if you are arguing to not use something because Firefox (and only Firefox) does not support it, you are going to have a fun time trying to convince most webdevs to care about just 2.77% of all internet users.
You're essentially saying "I want to use this months old API, and fuck you if you still have a browser from last year." People used to respect some amount of backward compatibility.
There's no reason to "respect" backwards compatibility in an inherently online product that auto-updates.
There's nothing ideological here, it's just about being practical.
But in this day and age of browsers being Chrome and Chrome and Chrome and Chrome and Safari, all with forced autoupdates, there's little practical weight behind "browser <X> doesn't support it!". If Chrome supports it, the internet supports it whether any of us like it or not.
I think, regrettably, that 2023 might be roughly the time where the "old browser" support consideration is finally put to bed.
For example, you no doubt have to perform all sorts of code contortions to make things work in old Internet Exploder. It means you have to use old coding methods compared to things that are quicker and easier to implement and get working cross-browser & cross-platform in modern CSS. It also means you are writing more LOC, which means more scope for weird little bugs and time-consuming troubleshooting.
Secondly (and perhaps more importantly), making things work in old browsers means you are removing further incentive for people to upgrade. Given the increasing prevalence of browser-based attacks where people can be pwned simply by visiting a website that contains "specially crafted code", I think the quicker everyone gets onto modern browsers the better...
Unsurprisingly we’ve had 0 issues asking our customers to use recent versions of Chrome/Edge/Firefox/Safari. Obviously not using super new APIs like @container before they are fully read on these 4 but still that’s still basically every modern feature.
Isn't it a deliberate choice to have that experience?
Unless you're in an industry that requires not upgrading, backward compatibility is great, up until a point.
But this means my glibc is also an old version. And this OS was released before docker existed in repos (and has no docker support). So I'm using an older brower with JS completely disabled. It displays HTML, text, images, etc pretty well. It's just the for-profit sites that used to cause problems. But now everyone is cargo culting the for-profit stacks, devs are expecting updates to browsers every 2 weeks, and it's getting harder for me.
So yeah, I expect it to be hard. But also, people have legitimate reasons for using old software.
I just went thru a similar page redesign and your layout experience resonate with mine. totally agree flex is probably the most overkilling choice here.
I end up not go with grid but old pal float in 3 col view, mainly bc my use case is not typical [L, M, R] -> [L, M/R] -> [L/M/R] layout pattern, but more complex [L1/L2, M, R1/R2] -> [L1/R1/L2/M/R2], and the variable height of each part make the height attribute very difficult to manage in 3 col view.
The last thing is mixins/functions, but not sure if there's an RFC for that.
Then we went through 25 years of dark ages where there were plenty of really great ideas for layout which were completely lost to horrible and competing and half-assed executions.
We are now finally in the golden age of layout where I can make something that looks great on all displays if I have the time and talent to do it. Sadly that is in short supply.
I think we have Chrome to thank for modern web design. Once the browser competition was completely and utterly crushed and everyone was forced to sign on to The One True Layout Engine the benevolent dictators at Google set things on the right path.
There are still edges cases (which JPEG replacement will win?!), but they are now blessedly few and far between.
I think it's less the dominance of Chrome itself and more the demise of Internet Explorer. The problem was that it didn't get updated like normal software, it was somehow tied to the OS, so old outdated versions lingered around for far too long, limiting what technologies web developers could use.
> There are still edges cases (which JPEG replacement will win?!), but they are now blessedly few and far between.
Last I heard was that the Benevolent Dictators at Google decided that AVIF shall win.
And let me take the opportunity to diss the failure that is mixing your styles into your layout with Tailwind and it's endless and illegible bloat of unreadable html.
Reading the bloated HTML is less painful than dealing with all the cascading crap.
Extra strong bold headline with super thin text for the body.