231 points · by brandrick · 3y ago · 96 comments
.special-wrapper {
--theme: dark;
container-name: stats;
}
@container stats style(--theme: dark) {
.stat {
/* Add the dark styles. */
}
}
Not to mention that half the problems in the blog post are completely manufactured:> That works fine, but if there is a space character within the <figcaption> element, it will fail.
Uh, yeah, that's how :empty works (it's not "empty"). If that's such a pain point, I'd propose a :no-children-but-maybe-empty pseudo-class before you add a completely new feature to the language, :but-maybe-that's-just-me.
/* Instead of.. */
html[dir="rtl"] .button-icon {
transform: scaleX(-1);
}
/* We do this */
@container state(dir: rtl) {
.button-icon {
transform: scaleX(-1);
}
}
Insert "they're exactly the same" meme. (Except for more curly braces: fun.)You're way too generous: the average developer couldn't do it.
You forgot grid areas.
CSS is so big, and only getting bigger all the time (just read the Chrome release highlights over the last few years, your head is going to spin just from the CSS additions alone), yet at the same time it's not a language (where you can typically get by with just learning the basics and start to write useful stuff real fast by relying on general algorithmization skill and programmer intuition), just a massive set of directives you can combine together, I really feel like at the point where it is all in your head and ready to go (i.e. you know what you're about to do, you do it and it does what you intended... without you having to go through a 10 minute Chrome dev tools & Stack Overflow intermezzo), you have to have such a good memory, that you would do much better as a lawyer or a doctor than "mastering css".
Is there some better universal styling solution than CSS? Probably not. Is CSS way, way too big nowadays? Hell yes.
You don't have to use named grid areas if you don't like. But honestly, why wouldn't you. grid-template-areas makes working with grid a walk in the park imo.
Also very few of us web devs know all of CSS by heart. We use tools and reference manuals all the time as we are working. I suspect no python developer knows all of python either and are constantly looking at documentation or hints from their language server/IDE. The real skill is knowing where to look, not what to write.
Can we make this a vote? My candidate is :emptyish
Agree, a `@container <complex-selector-list> <container-condition> {}` would be so much more ergonomic.
[1] Jim Keller talking about DNA Origami at 19:18, https://www.youtube.com/watch?v=gzgyksS5pX8
[2] Not even such a new idea, "Building a Better Web Browser - James Mickens - Harvard CS Colloquium 2015", on rendering at 04:20, https://www.youtube.com/watch?v=1uflg7LDmzI
The rendering engine can then be shipped along with the actual UI.
Sure, the rendering engine will take some time to load. However, compiling styling etc. to WebGL instructions at build time might also speed things up considerably.
(The actual reason, however, I'd be interested in this is not performance but improving upon the developer experience and replacing CSS with something better.)
I see no problem if instead of using all these web sites/applications with such a plethora of visual and experience spam, I just have a single input box connected to an agent through which I interact with them all, letting the APIs settle in the background.
Furthermore, concepts such as file systems, operating systems, networking protocols, and so on, are probably terrible abstractions, just the fact that a 10 year old printer is pretty much unusable with a "modern" operating system or that a VFD shipped yesterday from the factory can be rendered useless due to a single byte error in the Modbus connection ought to give second thoughts to anyone daring to call themselves an engineer.
But the dir can also be auto (especially on inline/quoted content, forms, or multi-language sites), so the browser decides what the dir state is. The example in the article could perhaps be clearer, so I think it's normal for one to think they are the same.
Please see: https://www.w3.org/International/articles/inline-bidi-markup...
Especially when you only have the container (perhaps you are designing a component library), reacting to state is much more secure, even though the browser support will haunt this feature for at least a year, or a couple of years to be more realistic.
For instance, in their `state(wrap: true)` example, now that the wrapping element is hidden, isn't it no longer wrapping? Why does the query continue to apply?
You can wave your hands around as much as you like but fundamentally this state based rule stuff says:
- apply styles
- now, query the current state
- based on the current state, apply different styles
I understand there are complex interactions that people want to cater for like sticky headers, but… really?
There’s only so far you can bandaid a declarative language like css.
If you want dynamic behaviour, use javascript. That’s why it exists.
I think container queries are cool and intuitively useful, much more so than queries based on what the browser window size happens to be.
These are not nearly as obvious to me. I get the nav bar scenario, but I think I find the quest for "CSS purity" where any design, no matter how dynamic, can be expressed without Javascript seems a bit silly. I have no problem with it, I just also don't think it's quite as noble as some seem to think.
I think you're missing the point. Adding functionality to CSS makes is mostly about separation of concerns and making desired features accessible to a wider audience than just JavaScript programmers.
And while a good programmer can do a lot with JavaScript, all of the machinery for layout—flex box, grid, container queries—is in CSS, so it makes sense to build on that.
It's interesting that CSS has been moving forward at a rapid pace to make extra tooling (LESS, Sass, etc) increasingly unnecessary, but at least from the layman's point of view (web dev isn't my bread and butter), HTML does not seem to be getting nearly as much attention. Clearly there's a need for more capable HTML as evidenced by the countless Rube Goldberg machines built atop it to make it usable, so why isn't there as much interest in developing it?
A lot of the machines built on top of HTML (e.g. JSX) add non-markup to HTML so you can handle if-else/filter and loop. But I don't think there's ever been interest in expressing that natively in HTML itself.
It’s confusing enough now that I would actually want some tooling to help.
I know that sort of thing really relies on the document that uses the CSS to be parsable somehow, but a lot of JS frameworks are writing templates that just look like HTML or JSX now.
1. A CSS stylesheet cannot be interpreted without a corresponding document (HTML, usually) with which to test CSS selector rules against.
2. Excepting static sites, HTML is generated dynamically, which means (thanks to our old friend, The Halting Problem) impossible (in the general case) for tooling to use static-analysis-based approaches for CSS linting when given even a basic document-outline or structure for, for example, a React/JSX application.
(CSS static-analysis also got 100x harder when the `:has()` selector was introduced, because it invalidates a number of optimizations possible due to CSS's original (and strict) "forward-only" design (i.e. before `:has()`, CSS selectors could only match elements based on their ancestors or previous-siblings: never their descendants or next-siblings, which also meant that selectors didn't need to be re-evaluated as the document's HTML was still being loaded)
-----
Existing tooling does what-it-can, for example, I've been often surprised at how well Visual Studio (not VS Code)'s HTML/Razor editor can make very reasonable CSS class suggestions when typing-out HTML - and while there's often good stuff in the Node/npm ecosystem, especially for typical frontend dev scenarios, like building SASS/LESS in a Grunt build), a common problem I've run into is the tooling breaking completely whenever I want to use an ultramodern CSS feature, especially those that introduce a new syntax - YMMV, of course.
I really like all this invitation that's happing with CSS at the moment, and I do believe it's coming from a place of ambition for the open standards. The standards process seems to be doing a good job of selecting the additions that other browsers have tested and committed to, so it doesn't feel like a "embrace/extend/extinguish" process from the Google Chrome team.
I know some people feel these additions are making CSS "too big", but the joy of it is that you can select what subset you want to use. The web platform is a platform for all, and that it what I love about it. You can build anything from a simple text page to a full blown application with one toolkit.
The browser implementation teams don't get to choose what to support, though. The argument is usually that a too big web platform will lead to a browser monoculture and increased control by one company.
The Webkit team's refusal to implement customized built-in elements sticks in the mind, not least because their reasons (and inability to describe an alternative) always sound more like a vendor pissing contest than any kind of engineering discussion.
I’m curious how successful they will be.
Today, all the money for this comes from only two companies in the world: Apple and Google (since Mozilla's main source of income is its deal with Google, we have three widely used rendering engines, but the money really comes from two companies).
Now what's interesting about Ladybird is it's this big pile of BSD licensed code that looks like it would be a good start if you wanted to build a fourth engine.
Is there someone out there who has a lot of money and a reason they would want to spend it on developing another engine? I.e. they don't want their fate owned by Apple/Google or the existing engines are somehow inadequate for their needs? This is the really interesting question.
This proposal is around adding a query for other properties on a container.
.button-icon:dir(rtl) {
transform: scaleX(-1);
}
However, it's not yet supported in Chromium browsers, so for now the attribute selector is as close as you can get.Because the CSS rules that define sticky only defines when something gets stuck, not that it's stuck. Ergo, it can say "this element becomes stuck when it's containing element is 200px from the top edge of the viewport", but until the user actually scrolls the document so that's true, the CSS rules that defined that doesn't make it stuck yet.
Personally, I'd settle for a pseudo class (e.g. `:stuck`, like `:active` I suppose). Currently I use an `IntersectionObserver` to dynamically toggle a `--stuck` class on my stickies, and I can target that as you describe it.
That would be a better framing for this feature. Given that framing, I can now see how it could be useful for things like custom controls not present in the set provided by the browser.
It would be interesting to see if browsers could use this mechanism internally to implement pseudo-classes.
#header:stuck {}
#nav:wrapped {}
I feel like we already have a system for states like this with :hover, :empty etc?Or am I missing something?
But this also unlocks a lot of other style query problems, like the cursed wrap detection. For some cases, container queries should also be sufficient. And contrary to many of the other responses here, yes I think this flexibility is important progress. There are tons of fairly straightforward (even trivially specified) layout techniques that are currently next to impossible without some combination of hardcoding measurements and/or JS, which are going to become reasonably achievable in the next year or two. That’s fantastic. And for everyone who complains about this complexity at the styling level, it’ll eventually eliminate the need for a whole class of runtime JS doing a whole bunch of inefficient calculations badly.
This is not at all like media queries or other meta states driven by some higher level operation. This is absolutely the wrong direction.
This change, when applied with css transition to split commands, would allow you to create loops, and enable you to implement the commands MOV, JMP, INC, and DEC. It should be possible to compile an arbitrary C program with just those commands (some papers have shown just MOV will do). In the most inefficient scenario, you should be able to draw a series of AND/OR and NOT/NAND gates to a HTML document, and colour in different outputs based on their inputs.
So CSS should be Turing Complete without caveats after this feature is introduced. I'm not sure what the output of such an application could be. I guess just the satisfaction of knowing that some computation is occurring, if that counts?
CSS can generate content, so it can actually output text like any other console.
https://accodeing.com/blog/2015/duty-calls-css3-is-not-prove...
https://accodeing.com/blog/2015/css3-proven-to-be-turing-com...
So yeah, it's most likely as powerful as our current computers.
.my-button {
padding: 1em;
goto: my-button-colors;
}
html {
label: my-button-colors;
background: white;
color: black;
}
@media (prefers-color-scheme: dark) {
html {
label: my-button-colors;
background: black;
color: white;
}
}
The most specific label will be jumped to. Labels follow the usual specificity rules (also including `!important`). Jumps to an invalid label are no-ops. Styles within a ruleset are evaluated top-to-bottom. Labels propagate to children.Of course the above example is silly. We also need to make sure we don't apply button styles to the `html` element. We can do that with a protective conditional goto using custom properties (aka variables). We can also make use of variables to implement returns:
.my-button {
--end: none;
--next: my-button-colors;
label: return;
goto: var(--next);
padding: 1em;
}
html {
--end: end;
label: end; /* Jump here to end a ruleset immediately. */
}
html {
label: my-button-colors;
goto: var(--end);
background: white;
color: black;
--next: none;
goto: return;
}
@media (prefers-color-scheme: dark) {
html {
label: my-button-colors;
goto: var(--end);
background: black;
color: white;
--next: none;
goto: return;
}
}Great. They have an army of devs working on something that you can't explain properly.
> That’s it for this quick post. What do you think?
Front end dev's look for new ways to find work. Impressively so.
We already mastered the css, then you came with scss (special, even though it transpiles to css)
"They let us query a container based on its width." -
UI devs looking for work.
Edit : Go into creativity/art whatever
You don't see any HTML advocates here.