Lurker News
Hey HN,

I'm a seasoned backend developer and systems administrator, with over 10 years of full-time programming experience. I've worked with anything from Assembly, C, Rust all the way to Python, Erlang, Elixir, PHP, Haskell, Lisp, Clojure.
When it comes to frontend, I have used React, Vue.js, ReasonML, Clojurescript and Elm extensively, and I know my way around web technologies in general. However, ever since I first started programming, I was NEVER able to get the gist behind CSS. I can't center my divs properly. I can't say "hey, CSS, this is the parent div, and all child divs must obey its size". I can't do anything basic on CSS without turning for help.
Incidentally, but very likely related, I always failed to have any glimpse into how design works. I have no idea which colors "go" with which ones, and pretty much all fonts look like the same for me.
I'd like to know the experience from fellow programmers. Is CSS an "art" thing? Is it common for other developers to have issues with it, or is it just me? Is there any material out there that made CSS "click" for you?

Comments (340) 150 threads

Earlier comments
open-source-ux1 reply#
Yes, it is horrible. It's got a little bit better (think flexbox and CSS grid) but it still feels clumsy, unintuitive, unpredictable, inelegant, frustrating. You learn to live with all it's painful shortcomings, but you'll never learn to like or love it.

Interesting aside: what would the creators of CSS do differently today?
Bert Bos:
- Feels there was too little detail in the first CSS spec (but Håkon Wium Lie thinks there wasn't enough)
- Wishes there were more ways to display link behaviour e.g. expanding/collapsing text
- He wanted to create CSS syntax that was readable for people who were not programmers
- He preferred a full stop (period) to mark the end of a group of statements. Curly brackets (braces) to group statements was Tim Berner-Lee's idea.
- Grids should have been a fundamental part of the CSS spec from the beginning
- Prefers the idea of CSS for documents and a separate language for UI elements
- Thinks the cascade could have been made easier
Håkon Wium Lie:
- Feels there was too much detail in the first spec: the more you added to the spec, the harder it became to implement
- Thinks that margin collapsing was too complicated for v1 and could have been dropped
- Also thinks first-letter and first-sentence pseudo-elements should have been left out of v1
- Hypercard was based on the idea of cards rather than documents - he wished a CSS card element had been defined
- He didn't want border radius originally, but designers insisted and he now likes it
- The v1 spec was written without any test documents - he considers that a major mistake
- They both approached CSS in a document frame of mind and wonders if they should have considered the idea of web apps more
Source: https://www.youtube.com/watch?v=PQTpsxf7rQQ

antod#
Interesting comments from those guys.

I taught myself CSS by reading the CSS 1 spec back in the late 90s (mainly aimed at IE 4 - Netscape 4.6 sucked bad) before there were any books on it. I think the CSS 2 spec was also out by then too, but the browsers didn't support it yet (that took a surprising long time).
I found learning CSS 1 from the spec pretty easy as it wasn't a large spec and was fairly easy to read. The CSS 2 spec was a lot larger (5-10 times?), and a lot more complex with all the new stuff. Learning that took some help from the old Eric Meyer book from O'Reilly with the pair of trout (?) on the front.
The Eric Meyer book helped a lot with understanding fundamentals like how flow worked etc and properly grokking inline vs block etc. There wasn't really any of the tooling (eg Firebug and successors) to help back then.
Of course, I wasn't reading the specs to implement a rendering engine - just to use it.
I stopped doing any CSS about 8 yrs ago just as CSS 3 was starting to happen and never really learnt that. It seems way more powerful/complex/useful these days.
One tip that really helped back then was to try and do what you wanted with the very minimum of selectors/declarations to avoid conflicts, ambiguities and debugging difficulty. So creating lots of scratch empty test pages to explore one specific technique before including it with all your other CSS/HTML.

tmm84#
I understand this feeling of CSS being some kind of black magic or something that just doesn't play by the rules. At almost every single place I work it feels like I am the only one who has a real grasp on CSS and makes stuff happen.

My personal advice is to take a website you are familar with and try and duplicate it with pure css and html. When you get good at simply writing it from scratch then you'll be able to understand it easily. You'll start to notice the red flag stuff, the useless UI libraries (useful is relative) and stuff that you could get done on your own easily.
My most important tool is the element inspector for any browser that isn't displaying as I expect it to.

h1d#
CSS isn't hard. It's design is broken on a few things which makes it look more complicated than it should.

I've done web for 20 years and I still Google around when it comes to aligning things vertically centered and I sometimes fall back to using tables for layout because it's still the most stable way to keep stuff at where it should be.
And of course the way you need to declare in a very redundant way for selectors on multiple elements is annoying but we have at least sass and my preference is using stylus (combined with pug) which removes a lot of those unnecessary declarations go away with the ability to define variables in 1 file and use it all over.

rntz#
> Incidentally, but very likely related, I always failed to have any glimpse into how design works. I have no idea which colors "go" with which ones, and pretty much all fonts look like the same for me.

This is not related. There is no magic or natural connection between grokking CSS and having a sense for color theory or typography. They are connected by circumstance only, in that they're all useful for web design, and in that CSS can control colors and typography in the web browser. CSS is not any more an "art" thing than Javascript or C, although it is a thing with which one can make art (as are Javascript and C).

Load more comments