Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am increasingly worried about the “smart” CSS solutions. The spec is already huge, the selectors are hard to read and google, the interplay between various features is devilishly complex. And the CSS community seems to be very fond of these smart hacks where people in the know say “Oh, that’s just Foo’s variation on Bar’s flex owl hammer” and you are left to study the CSS lore for hours to decrypt the two or three letters. I just wish we would value simplicity over cleverness.


CSS is one of the languages that everyone shits on because they never bothered to learn it properly. When you learned your programming language of choice you probably read a formal tutorial, or followed a full fledged course. Well once you spend some time learning CSS, it becomes incredibly easy to do almost everything you want.

If you know your basic CSS selectors `.stack > * + *` is very easy to understand. I didn't know `* - *` was sometimes referred to as "lobotomized owl selector" but it doesn't matter, `>`, `*` and `+` are all basic selectors that everyone working with CSS should know from the top of their head. None of these are "clever". If you can't read `.stack > * + *`, you don't know CSS selectors. I'd even argue if you don't use mostly `>` instead of ` ` (space selector) your stylesheets are probably unmaintainable.

CSS hacks were a shit show 10 years ago because of browser compatibility, but the thing presented here is not a hack, it's just a useful rule.


> I am increasingly worried about the “smart” CSS solutions.

I'm not worried.

> The spec is already huge, the selectors are hard to read and google, the interplay between various features is devilishly complex.

Actually things are getting less complex due the fact we don't need to use all of the hacks, work-arounds and polyfills that were once just what pretty much every web developer did not that long ago. And of course, the original sin of the misuse of HTML tables for layout.

Sure, it wasn't fun to deal with new specs coming out while trying to maintain existing code and attempting to understand when (or if) we can use the new stuff. Sometimes is was like trying to fly a plane while the plane is being retrofitted with new features.

The irony: many of the techniques described in the article is how we should have been doing things for along time. Hayden's article [1], which is the basis for this, was published nearly 10 years ago—these concepts aren't new.

[1]: https://alistapart.com/article/axiomatic-css-and-lobotomized...


> And of course, the original sin of the misuse of HTML tables for layout.

Hardly a sin - there were no alternatives at the time (1996 - 1998) if you wanted a tabular or grid layout.


Sure, but developers continued to use tables long after there were alternatives.

The first edition of Zeldman’s seminal book Designing with Web Standards [1] was released in 2003; two additional editions were released in 2007 and 2009.

[1]: https://en.wikipedia.org/wiki/Designing_with_Web_Standards


Maybe I'm just old as shit but this is nothing compared to some of the selector hacks we had to do back in the IE6/IE7 support era.

This isn't to say those hacks were good, mind you - just that their existence was never really a problem insofar as ability to understand them if you dealt with it once.


The bit about googling is correct. But I posed it to ChaTGPT and it explained it immediately.

Having said that, I also knew what it did immediately upon reading it, and I am not a CSS expert. One you know a little bit about selectors, then you should be able to decode this one rather easily.


It will explain anything immediately. Correctly, not necessarily. Did you check the explanation holds water? Seems like it's back to googling anyhow.


Maybe save us all the trouble and either copy-and-paste the robot's explanation, or share your own.


Asking ChatGPT to write html / css / tailwind is my favorite application so far.

I still can’t remember how to horizontally and vertically center an element but CGPT sure can.


I think CSS and the domain of laying out things in 2d (and responding to state changes) with code is actually inherently complex, so which ever layout system you use is going to have a steep learning curve.

Many of the newer CSS features prevent you using JavaScript to achieve the same thing, which is better as it results in better performance and easier to understand code.

I would rather have newer standardised selectors than see the same pattern re-implemented with JS differently in every codebase.


Better a single smart and simple CSS one-liner like this accompanied by an article link in the comment than a gazillion repeated CSS classes and exclusion rules.


I had the exact same sentiment when the arrow function was added to JS. My mind has not been changed in the years since. Clear is always better than clever, arrow functions are not clear (despite the desperate cries to the contrary by complexity loving programmers).


Of all the JS features you are picking the arrow function? Is it the syntax, or the this binding thing that works differently than function expressions / statements you are complaining about?

Because the syntax looks somewhat like the function notation in math, and a variation of it is also present in many programming languages, often functional, but also Java since version 8. It's quite widespread and not very bizarre / specific to JS.

You'd have mentioned tagged templates [1], I'd have to bow.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


The syntax. I don’t see how prior use in mathematics or other languages has any bearing. JavaScript could have led the way by using a clear syntax instead of perpetuating complexity.


> how prior use in mathematics or other languages has any bearing

It counts, because it makes it familiar to many people.

Had JS introduced this syntax without it being anywhere else I would be completely with you: it would just be weird and unnecessarily complicated.

I find this syntax very clear too (though I still prefer function () { ... } for most functions). It has the merit to make some code using small functions, often somewhat functional, lighter to read. But this is a matter of taste, of course.


So that's how test.each works in jest!! Catharsis!


Ah, so it's actually used somewhere, and in a widespread tool above all? :-)


Like some sort of perverse Andy and Bill's law, the more powerful CSS selectors we have, the sloppier document structures get.


They're not that complex if you understand CSS

And let's face it… to understand the example code you only need understand what > + * do in CSS

Using intrinsic sizing, and the sorts of approaches Andy Bell suggests reduces the volume of CSS enormously and can often get rid of media queries and huge numbers of selectors that get repeated across viewport sizes

I'd really encourage you to watch this talk by Andy https://www.youtube.com/watch?v=5uhIiI9Ld5M


It is one of those things as an outsider you think that something is overly complex, and then you learn it, and understand that it's complex because the issue it is tackling is dynamic which often requires a level of complexity to apply over.

I had the same thought with Regex before learning it. Now I can read it like css selectors, and you'll notice that the complex patterns are that way because they have to cover dynamic situations (using ranges, lookbehind/lookahead, etc).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: