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
acjohnson55#
In reference to a sibling comment (https://news.ycombinator.com/item?id=19021837):

> CSS is very much like magazine or print layout IMO. If you're not used to that, it won't gel well. If you think of layout from a design perspective and _not_ a programming perspective, it's really not that bad.
Yes! I went looking for this comment before adding it myself. Although I chose not to reply, since that's only part of what I want to discuss.
Once I realized that CSS is exactly what would make sense for laying out a textbook, it clicked for me. Until a few years ago, web design implementation was hacking this model to realize application and widget layouts.
Nowadays, flexbox and grid are basically universal, and we can use them as we please to do proper 2-D layout, and then use classic CSS for textual flow. It's a wonderful time.
But to go beyond that mismatch of expectations, the other historical problem with CSS is how to organize it in a reasonable way. Typically, you need a number of rules to apply to related elements in order to achieve some specific effect, but these get all jumbled with other effects that need to reference overlapping sets of elements. Combine this with the fact that CSS offers a crap-ton of features that you rarely need, especially in the selector spec. Preprocessors and methodologies like SMACSS and especially BEM helped give us ways to tame the madness. The BEM website (https://en.bem.info/) is a great resource for this.
This is all front-end dev skills that most of us learned by thousands of articles and hard knocks. I wish I could point you to a bible for this, but I don't know of one.
When it comes to design, that's its own skillset, which really may have little to do with CSS. Many of the designers I've worked with don't know how to implement their designs in CSS (although that's not always the case). The principles of good design ultimately come from the goals of the product, mixed with usability concerns and, of course, fashion.

squirrelicus#
I'm also a seasoned back end developer. It took me 3 years to become a beginner at CSS, and two more to feel like I could finally style an arbitrary front end at an intermediate skill level. This is in comparison to 1 year to master javascript and another year to "get" React top to bottom. CSS was even harder to learn than ansible or clustered mongodb at scale.

I suspect it's a neurological difference. I've seen masters of CSS struggle with basic operational computing concepts that feel obvious to back end developers.

wbkang1 reply#
> I can't center my divs properly.

This is actually pretty simple, once you understand how "block" elements work. Block elements will always try to fill up the "available width" i.e., they stretch side ways. The sum of margin + its width must match the total width.
Inline elements will fill up its parent block like text.
So, a simple example - suppose you set a div's width to 100px, and margin to auto, then you will a 100px wide box centered.
I see people get confused when they try to have a block that has an unspecified width and hope CSS just figures out.

ken#
> This is actually pretty simple, once you understand how "block" elements work.

I disagree -- in this and every case where someone has told me that something is simple once you understand the fundamentals. Understanding how a tool works is completely different from understanding how to use it to accomplish a particular goal. One's a deconstructive process, and the other is a constructive process.

androidgirl#
CSS positioning woes are brutal- until you have the knowledge from previous struggles.

Full disclosure, I am artistic, but imo css is a different skillset.
You'll have knowledge on when to use flex, floats, or the new css grid, be able to center behind text, and all the other traditionally tricky things.
Honestly, just practice, don't give up!For layout specifically, Flexbox can solve almost any problem. Once I "got" flexbox I was having an easier time. And CSS-Grid can solve almost everything else!

Load more comments