TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Future CSS: State Container Queries

231 pointsby brandrickalmost 2 years ago

20 comments

dvtalmost 2 years ago
Is this really the way forward? I&#x27;m pretty sure implementing CSS from scratch (just looking at the specs) would take the average developer at least 10,000 hours. But in any case, why doesn&#x27;t the container query bind to a class? Having to name your container is so weird (we already <i>have</i> names: they&#x27;re called classes; and IDs; and DOM elements; and pseudo-classes; and aria labels; we need more!?).<p><pre><code> .special-wrapper { --theme: dark; container-name: stats; } @container stats style(--theme: dark) { .stat { &#x2F;* Add the dark styles. *&#x2F; } } </code></pre> Not to mention that half the problems in the blog post are completely manufactured:<p>&gt; That works fine, but if there is a space character within the &lt;figcaption&gt; element, it will fail.<p>Uh, yeah, that&#x27;s how :empty works (it&#x27;s not &quot;empty&quot;). If that&#x27;s such a pain point, I&#x27;d propose a :no-children-but-maybe-empty pseudo-class before you add a completely new feature to the language, :but-maybe-that&#x27;s-just-me.<p><pre><code> &#x2F;* Instead of.. *&#x2F; html[dir=&quot;rtl&quot;] .button-icon { transform: scaleX(-1); } &#x2F;* We do this *&#x2F; @container state(dir: rtl) { .button-icon { transform: scaleX(-1); } } </code></pre> Insert &quot;they&#x27;re exactly the same&quot; meme. (Except for more curly braces: fun.)
评论 #36513788 未加载
评论 #36515317 未加载
评论 #36517611 未加载
评论 #36514934 未加载
评论 #36513590 未加载
评论 #36516729 未加载
评论 #36517247 未加载
评论 #36518156 未加载
评论 #36517387 未加载
wbobeirnealmost 2 years ago
Interesting to see this, as I feel like I&#x27;ve seen arguments against this kind of state-based querying come up to avoid cases where you end up with an infinite loop of state query applying -&gt; new styles applying -&gt; new styles undo the state -&gt; state query not applying -&gt; styles removed -&gt; original state query applying, repeat indefinitely. I believe this was the rationale for not having pseudo states for when a container is scrollable, for instance. I wonder what they&#x27;ve done to avoid these cases.<p>For instance, in their `state(wrap: true)` example, now that the wrapping element is hidden, isn&#x27;t it no longer wrapping? Why does the query continue to apply?
评论 #36514786 未加载
评论 #36512710 未加载
kitsunesobaalmost 2 years ago
Really cool, seem like it&#x27;d make styling responsive pages considerably more easy.<p>It&#x27;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&#x27;s point of view (web dev isn&#x27;t my bread and butter), HTML does not seem to be getting nearly as much attention. Clearly there&#x27;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&#x27;t there as much interest in developing it?
评论 #36512516 未加载
评论 #36513579 未加载
评论 #36514922 未加载
graypeggalmost 2 years ago
Is there an IDE out there with really good CSS+HTML intellisense&#x2F;tools? Not just like suggesting standard properties but actually keeping track of rule usages, refactoring duplicate rules into a single class, jump to related rules (maybe a media&#x2F;container&#x2F;state query somewhere else also affects a rule) that sort of thing.<p>It’s confusing enough now that I would actually want some tooling to help.<p>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.
评论 #36513866 未加载
评论 #36516262 未加载
评论 #36517055 未加载
samwillisalmost 2 years ago
This looks like a very welcome addition, I will certainly be using it if it makes it to standard. I&#x27;ve often had to resort to JS to &quot;detect&quot; when my sticky elements are stuck before.<p>I really like all this invitation that&#x27;s happing with CSS at the moment, and I do believe it&#x27;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&#x27;t feel like a &quot;embrace&#x2F;extend&#x2F;extinguish&quot; process from the Google Chrome team.<p>I know some people feel these additions are making CSS &quot;too big&quot;, 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.
评论 #36513527 未加载
评论 #36512908 未加载
stabblesalmost 2 years ago
CSS has a feature creep that makes it harder and harder to write a new browser from scratch
评论 #36514993 未加载
评论 #36513662 未加载
wouldbecouldbealmost 2 years ago
Yeah that&#x27;s main thing missing, media queries should have been &quot;relative&quot; to its parent from the start not window absolute.
评论 #36512269 未加载
评论 #36512037 未加载
cjpearsonalmost 2 years ago
The last case could be covered by the `dir` pseudo-class.<p><pre><code> .button-icon:dir(rtl) { transform: scaleX(-1); } </code></pre> However, it&#x27;s not yet supported in Chromium browsers, so for now the attribute selector is as close as you can get.<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;:dir" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;:dir</a>
quickthrower2almost 2 years ago
If you need to style something when it is stuck, why not make the css class that made it stuck include that style?
评论 #36513955 未加载
Liquidoralmost 2 years ago
I like these however why not just use pseudo-selectors instead of a named container?<p><pre><code> #header:stuck {} #nav:wrapped {} </code></pre> I feel like we already have a system for states like this with :hover, :empty etc?<p>Or am I missing something?
somisherealmost 2 years ago
So, IMO what is actually cool about this is it will allow you to detect scroll position without JS, which opens up a whole bunch of very nice posibilities!
评论 #36515065 未加载
incrudiblealmost 2 years ago
Just give up and add JS to CSS already.
评论 #36525723 未加载
Repturalmost 2 years ago
Can we not over-complicate CSS? Innovation is supposed to be _easier_ not more complicated.
dclowd9901almost 2 years ago
Oh my god, no. Why is presentational description language being used to _query the very presentational state it’s creating_?<p>This is not at all like media queries or other meta states driven by some higher level operation. This is absolutely the wrong direction.
评论 #36515092 未加载
miohtamaalmost 2 years ago
Is CSS Turing complete yet?
评论 #36513008 未加载
评论 #36512683 未加载
评论 #36512883 未加载
评论 #36516818 未加载
sachahjklalmost 2 years ago
the wrap detection for flex elements would be really nice to have. Kind of mind boggling that it&#x27;s not already in the spec.
idk1almost 2 years ago
Cool! Where can I find a list of all `container-type`s and their equivalent states? It looks like there&#x27;s so many.
Alifatiskalmost 2 years ago
This blog has some other tasty stuff like ishadeed.com&#x2F;article&#x2F;comment-component
progxalmost 2 years ago
You might as well add if, then, else, functions, do, while, switch, ...
评论 #36518805 未加载
bilekasalmost 2 years ago
&gt; The Chromium team is experimenting with a new type of query, which is called State Query<p>Great. They have an army of devs working on something that you can&#x27;t explain properly.<p>&gt; That’s it for this quick post. What do you think?<p>Front end dev&#x27;s look for new ways to find work. Impressively so.<p>We already mastered the css, then you came with scss (special, even though it transpiles to css)<p>&quot;They let us query a container based on its width.&quot; -<p>UI devs looking for work.<p>Edit : Go into creativity&#x2F;art whatever<p>You don&#x27;t see any HTML advocates here.