Live data from Hacker News

WebKit Supports Nested CSS

webkit.org

171–180 of 183 posts

Re: WebKit Supports Nested CSS

#171
Another benefit I'm not seeing is that sass/less/minifiers can now target this new native nesting for the output, which would reduce the overall byte size of the output.

So you don't need to use nesting in your code if you don't want to, but can still take advantage for smaller minified css files using a transpiler.

Re: WebKit Supports Nested CSS

#172

Sanity has prevailed! Great work from the WebKit team, leading the way here. Not to mention great solve on the `color: blue` fiasco. Balances an edge-case compromise nicely, and leaves it open to future improvements. Bravo.

Fwiw, while I deeply appreciate WebKit supporting the proposal as well, the editors of the Nesting spec are Googlers and the Chrome impl happened at the same time.

Worth a lot! Thanks for clarifying. You need to give your product manager / blog team a kick :)

Re: WebKit Supports Nested CSS

#173
post #108

Earlier quoted context omitted.

unpopular opinion I'm sure from reading everyone here, but to me nesting css is syntactic poison - or maybe syntactic sucrose or something that gives you cancer you use too much of it? Anyway programmers given nesting just do it all the time which ends up leading to stuff like article.news section.preamble h1 and probably a few other selectors after that all nested giving you a wonderful high priority for your style…

I agree with you. I worked in several codebase that used SCSS and due to those little hacks popping up in review, every time we ended up putting a "rule" in place to stick to two levels of nesting at most, or 3 if you're using the third nesting-level for pseudo-selectors (:hover :before etc). And this rule very rarely had to be broken, as it was extremely easy to avoid being too clever with nesting. (Of course, if th…

Yup, I had a stylelint rule specifying no more than 2 levels.

Re: WebKit Supports Nested CSS

#174
post #117

Earlier quoted context omitted.

Historically the webkit team has pushed the web possibilities a lot. Just take a look at the amount of APIs that you had to add the `webkit` prefix, for example. Not sure if you work with browsers, but constantly you meet something that they implemented first. I honestly think that developers are very wrong when they think that Safari/webkit is slowing the web down. Yes, some things like lack of notifications etc are…

It's not just getting those features implemented, but also shipping those to the user. Safari is the only browser that doesn't have autoupdate and has versions tied an operating system in 2023 and that's one of the biggest problems. While you can be happy only supporting say the last version of all other browsers, Safari requires you to give it years before the marketshare of the new versions are enough that you can…

Funnily enough they JUST released a blog post talking about how they are going to improve some of these missing PWA functionalities at:

https://webkit.org/blog/13878/web-push-for-web-apps-on-ios-a...

https://news.ycombinator.com/item?id=34823402

Re: WebKit Supports Nested CSS

#175

Earlier quoted context omitted.

> Hard to see the use-cases for sass in 2024 Modules make writing CSS much less of a naming game. Anything you can do to reduce one of the 2 hardest problems in CS is worth it.

Or build a design system with good names and take advantage of the global nature of standard CSS.

Making sure that the top-level classes of components are unique isn't difficult. Making sure the inner classes are unique (yet still follow a consistent naming convention) is only possible with a methodology like BEM, which is clunky. And you want inner classes to be unique so that you can nest components safely without having outer components accidentally styling the innards of inner components.

Re: WebKit Supports Nested CSS

#176

Earlier quoted context omitted.

Relevant links on this: https://twitter.com/LeaVerou/status/1580215877705687040 , a poll about this specific matter (with links to other relevant polls which on the surface contradict this one). https://github.com/w3c/csswg-drafts/issues/7834#issuecomment... , on this exact matter (chosen as a convenient starting point, after matters were already settled, but the whole issue is about it). By the time this poll was do…

It's not a lot of code to implement, but it greatly simplifies usage by eliminating ambiguity: - Easier for human readers (the "&" is an unmistakable visual indicator) - Easier for human writers (fewer decisions; there's Only One Way To Do It) - Easier for syntax colouring

I agree with the rest, but requiring & won’t make it easier for syntax highlighting, because that & can be anywhere in the selector, not just the start; the & affects nothing in determining whether it’s a rule or a property.

Re: WebKit Supports Nested CSS

#177

Earlier quoted context omitted.

It's not a lot of code to implement, but it greatly simplifies usage by eliminating ambiguity: - Easier for human readers (the "&" is an unmistakable visual indicator) - Easier for human writers (fewer decisions; there's Only One Way To Do It) - Easier for syntax colouring

I agree with the rest, but requiring & won’t make it easier for syntax highlighting, because that & can be anywhere in the selector, not just the start; the & affects nothing in determining whether it’s a rule or a property.

I'm saying the "&" should be required _at the start_.

Perhaps controversial, I know. I realize this eliminates use cases like

    em {
      color: green;
      li & {
        color: red;
      }
    }
It's okay not to support these use cases. They're confusing because they break encapsulation; the rule that appears to be nested inside (in this case, color: red) is affected by an element on the outside (in this case, ).

Compare:

    li {
      color: blue;
    }
    em {
      color: green;
      li & {
        color: red;
      }
    }
To:

    em {
      color: green;
    }
    li {
      color: blue;
      & em {
        color: red;
      }
    }
The second structure is easier to understand, and in my opinion, the syntax should bias you toward writing it that way.

Re: WebKit Supports Nested CSS

#178

Earlier quoted context omitted.

Yeah... the only difference _in terms of nesting_ that I'm aware of is exactly as discussed in the blog post: you must start a nested section with a symbol. Sass itself has a huge amount of features... is the expectation that we should just adopt a Sass implementation into the browser or something?

The other difference is that SCSS nesting can also be used for string concatenation, as in BEM classes. Such as: .some-class { color: red; &__child { color: blue; } } Which compiles to .some-class { color: red; } .some-class__child { color: blue; }

Oh right I kinda hate that and feel like it leads to strangely named classes

Re: WebKit Supports Nested CSS

#179

Earlier quoted context omitted.

I agree with the rest, but requiring & won’t make it easier for syntax highlighting, because that & can be anywhere in the selector, not just the start; the & affects nothing in determining whether it’s a rule or a property.

I'm saying the "&" should be required _at the start_. Perhaps controversial, I know. I realize this eliminates use cases like em { color: green; li & { color: red; } } It's okay not to support these use cases. They're confusing because they break encapsulation; the rule that appears to be nested inside (in this case, color: red) is affected by an element on the outside (in this case, ). Compare: li { color: blue; } e…

This functional limitation was eliminated from consideration long ago: it’s very common to want that functionality. There were options considered for still denoting nesting, e.g. start all nested chunks with @nest, but this was decided to be inconveniently verbose. I think & is safe from being inconveniently verbose, but you can’t sanely use that without the functional limitation.

On your example: nesting is not about the sort of encapsulation you think it is—that’s incidental at best. It’s perfectly reasonable to say “this chunk of styles is about elements; and when they’re inside , do this”. The specific example you’ve given is also unrealistic with all three rules touching the same property in this way and two mutually exclusive (that is, li and em cannot both match, in any DOM), and I wouldn’t want it written with nesting at all, but rather like this, for much-increased clarity:

  li {
      color: blue;
  }
  em {
      color: green;
  }
  li em {
      color: red;
  }

Re: WebKit Supports Nested CSS

#180

I am not a big fan of nesting. I have yet to see a codebase where nesting makes CSS more readable. Even with BEM, I find it easier to reason about (and debug) the vanilla style. However, I must admit that `&:hover{}` does have a certain appeal. Also, I am very happy that nesting can be done without tooling in the future. It's a feature that many people love.

I agree, for some reason my brain sees the non-nested versions of CSS as more readable. Although we seem to be in the minority here. Very open to trying out nesting and perhaps my brain will 'flip' to eventually prefer it.

it comes down to the Inspector for me. I've had zero problems thus far right clicking on elements and then clicking on the relevant CSS exposed. I don't think anyone should actually be reading through CSS docs (will admit I'm a solo dev here so got it easy), and I'm afraid this could make the Inspector more confusing.

furthermore I suspect a very large % of people do not realize you can actually edit and save your CSS directly with Workspaces.

Post reply on HN