2 ms·
CSS doesn't have explicit "if" because it's a logical language, and thus every single thing you write is an "if". The only things missing from it having univer
by marcosdumay 4y ago
CSS doesn't have explicit "if" because it's a logical language, and thus every single thing you write is an "if".
The only things missing from it having universal logic are coming with the ":has" selector. So there isn't anything to argue about performance. The new ":has" is a performance killer, everybody knows it, nobody really cares because it's only a problem if you abuse it... and of course people will make a point of abusing it.
Interestingly, it is also getting predicate composition, with hierarchical selectors. Looks like the CSS people finally decided to turn it into a usable logic language. The auto generated sites have huge amounts of them because both auto generated code tends to be bad, and because it lacks composition. One of those is being solved.
- zamadatix 4y agoThere are definitely selectors that have more of a performance impact than others but they still don't allow you to break some general assumptions. E.g. taking :has() the addition is styling an element base on a relative selector anchored to that element but it doesn't allow for arbitrarily anchored selectors or matching things which could result in cycles. A lot of what browser engines did to make that work reasonably fast like here https://twitter.com/anttikoivisto/status/1473251189181591554 https://twitter.com/anttikoivisto/status/1473251189181591554 might not work efficiently with something less restrictive such as a true general purpose if(). I'm not familiar with what you're referring to with hierarchical selectors. CSS combinators have always let you select different types of decedents and :has() lets you select either way. Are you referring to Cascade Layers, or maybe something else?