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
c-smile#
CSS is simple.

It uses two basic constructs: rule and its selector.
Selector is SQL's SELECT/WHERE statement essentially that says:
When the element conforms this condition it has these set of properties. Any element may have multiple rules applied with matching selectors in particular order (so called CSS specificity).
And there are 20-30 basic CSS properties defining different aspects of layout and rendering.
Yes, there are 200+ other properties (and counting) in the full set. But that's for Jedii and merely 10-20 of us who are in business of creating layout engines.
It used to be more of us but the ones from MS are lost for the Republic - all their events were bubbled up onto the Dark Side.

joe8756438#
CSS is not hard. Design is hard. Putting a technical barrier between yourself and a decent design makes designing a little harder. But CSS is just obscuring a really tough problem. One thing that makes CSS seem tough is its incompatibility with the design process. A "simple" design change can mean many many lines of CSS or CSS that is simply incompatible with existing CSS/HTML structure. The best CSS writers I've known all have backgrounds in design/art. It's a long term play, but I'd say invest in learning to design. Forget about CSS for a while.
eswat#
How many hours have you spent writing CSS versus the programming languages you mention?

I don't think there's any art to writing CSS or having an easier time with it. It's just putting in the hours to know what works and the energy to understand the foundations (box model, cascading, etc. which are concepts you only need to commit to memory once).
Maybe CSS clicks better with some people, but the others can offset it with time. When I started writing CSS 15+ years ago I never thought I'd be able to do anything useful with JavaScript. But then you put in the hours…

Falkon1313#
What you discover about CSS is that it's an accretive thing. You start out perhaps with a (comparatively) simple basis, whatever came with whatever app or framework your site is based on, or if you're lucky and starting from scratch, what you yourself wrote and understand.

Then over the years, you and other developers and designers on the team add to the CSS. You can't go back and change anything, because changing something to look right on this page may make it look wrong on another page. You can easily see the structure of selectors on the page you're looking at, but not the set of all possible selector structures on every possible potential page on the site to know how it will cascade everywhere. So you just add on, gradually getting more and more specific with the selectors up to the point where you have to start using !importants.
Meanwhile, over the years, the 'best practices' change, and the CSS that you and your coworkers write changes to adapt. So you end up with things originally sized in pixels, later multiplied by a floating point scaling, overridden with em measurements, overridden by whatever the current fad in measurements is. Change any of that and it breaks random things throughout the site due to cascading, inheritance, and document structure/selector specificity.
Due to the way it accretes over time, you end up with massive amounts of CSS, most of which is overridden but can't be removed without breaking random things. You can't reconcile it or do it the right way without a full rewrite.
And in the end, it still always takes a few hours to figure out how to center something without breaking the alignment of other things, or whatever you're trying to do. Because it will be different than it was last time. It's not like just calling element.align(vertical=center, horizontal=center); as it would be in a programming language. It's a series of hacks built upon hacks to do the most basic things.

Load more comments