News for hackers. Stuff that matters.
Re:Conditional CSS with:has and:nth-last-child by samwillis on Wednesday May 17, 2023 @02:25PM (#35979301)
There are so many nice new things in CSS, along with :has() and :nth-last-child there is also :is(), :not() and the new nested syntax. All make working with raw css much more pleasant. No more SASS/LESS, and (hopefully) soon no more PostCSS hopefully!

:is() - https://developer.mozilla.org/en-US/docs/Web/CSS/:is

:not() - https://developer.mozilla.org/en-US/docs/Web/CSS/:not

CSS nesting - https://developer.chrome.com/articles/css-nesting/

Interestingly nested css is implemented as a syntactic sugar over :is() in order to achieve the correct specificity.

Re:Conditional CSS with:has and:nth-last-child by ozzmotik on Wednesday May 17, 2023 @02:59PM (#35979670)
x
Re:Conditional CSS with:has and:nth-last-child by paavohtl on Wednesday May 17, 2023 @05:16PM (#35981367)
Little nitpick, but :not() is not a new feature by most definitions of new. It has been in browsers for over a decade (closer to 15 in browsers not related to IE), which is an eternity in the world of web technology.
Re:Conditional CSS with:has and:nth-last-child by samwillis on Wednesday May 17, 2023 @05:32PM (#35981514)
Correct, although :not() had a massive upgrade only a couple of years ago with complex selectors support.

Prior to the change you could only pass a "simple selector" that only matched against the one node, such as :not(.something).

However you can now do :not(ul > li p.something)

Re:Conditional CSS with:has and:nth-last-child by jimmaswell on Wednesday May 17, 2023 @05:37PM (#35981572)
> HTML elements currently require the & symbol in front or being wrapped with :is().

They were so close to capturing how good LESS is, why did they do this? Why didn't they just copy LESS?

Re:Conditional CSS with:has and:nth-last-child by samwillis on Wednesday May 17, 2023 @05:42PM (#35981628)
It's to do with how the parsers are implemented in browsers I believe. I think I read that it would require a large rewrite of them all and potentially make them slower.

Personally I think it good that it makes it more explicit, even for none element nested selectors I'm adding the & to make it clear. So for a class "& .something".

Edit:

Found it in the spec

> Nesting style rules naively inside of other style rules is, unfortunately, ambiguous—the syntax of a selector overlaps with the syntax of a declaration, so an implementation requires unbounded lookahead to tell whether a given bit of text is a declaration or the start of a style rule.

> ... that is, the parser might have to hold onto an unknown amount of content before it can tell which way it’s supposed to be interpreting it. CSS to date requires only a small, known amount of lookahead in its parsing, which allows for more efficient parsing algorithms, so unbounded lookahead is generally considered unacceptable among browser implementations of CSS.

End of this section: https://www.w3.org/TR/css-nesting-1/#nesting

Re:Conditional CSS with:has and:nth-last-child by foolip on Wednesday May 17, 2023 @05:55PM (#35981757)
The CSS Working Group has resolved to relax the syntax in https://github.com/w3c/csswg-drafts/issues/7961 so what you desire is coming :)
Re:Conditional CSS with:has and:nth-last-child by jimmaswell on Wednesday May 17, 2023 @09:31PM (#35983268)
That'll be great. One wart I'm tired of dealing with in LESS is having to escape every use of calc() or else the preprocessor tries to do it itself.
Re:Conditional CSS with:has and:nth-last-child by hanniabu on Wednesday May 17, 2023 @06:24PM (#35982002)
I've gone vanilla css since variables were added
Re:Conditional CSS with:has and:nth-last-child by Waterluvian on Wednesday May 17, 2023 @08:23PM (#35982837)
Agreed. This really feels like an ES6 moment for CSS.
Re:Conditional CSS with:has and:nth-last-child by porker on Thursday May 18, 2023 @01:07AM (#35984300)
> No more SASS/LESS, and (hopefully) soon no more PostCSS hopefully!

I keep running my CSS through SASS just so I can use single line comments. If they'd add those to CSS natively...

Can't wait to drop PostCSS as I've had its plugins, extensions, whatever they're called break my stack (through subtle bug or breaking changes) more often than Webpack plugins, and that's saying something.