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
foxfired1 reply#
I remember when I first told my colleagues that I followed every single CSS course on Lynda, they laughed. They thought why would you spend all this time on a non programming language?

No one takes CSS seriously. For most, CSS comes as an after thought. Build every part of the application then suddenly "Oh Right! CSS!" Slap bootstrap or other popular framework then don't think about it.
Yes, CSS is not a programming language like others but it is just as complex. It requires studying, practice and long exposure to become versed in it.
Note: you can google your way into using a couple jquery functions, but you can't become a competent JavaScript developer like that. The same goes for CSS.

flukus#
> Build every part of the application then suddenly "Oh Right! CSS!" Slap bootstrap or other popular framework then don't think about it.

It depends on the problem your trying to solve, if you just want something that looks decent (because you're a programmer and you don't notice things like colors, alignment and spacing) then something like bootstrap is a good go-to.
I still think learning CSS properly is worth it, using bootstrap without knowing CSS is like using an ORM without knowing SQL, but less dangerous.

elviejo6 replies#
CSS is almost a failure as technology. None of it's promises has been realized.

The idea with CSS was that we would be able to separate content from presentation. Remember CSS Zen garden? Yet that has never been the case and div tags were always needed to be able to display something simple.
Another promise was that content would be displayed easily on different mediums, desktop, mobile even print.. yet it's impossible to get decent rendering in every medium.
For the first years of CSS it was always easier to get a decent layout with tables than with it.
Finally all the CSS preprocessor, like saas and compass show how incomplete the technology really is.

mattlondon1 reply#
CSS Media queries allow you to trivially handle different mediums (screen size, pixel density, screen-vs-print etc). It really is very very easy.

I dont agree that CSS preprocessors are evidence that the technology is incomplete. Does a c/java/golang/etc compiler mean that x86 is incomplete or somehow flawed? I would wager that most programmers wouldn't agree with that. CSS preprocessors are basically just a way of saving time and improving maintainability by "compiling" some syntactic sugar down to "raw" CSS. Same could be said with doing assembly programming vs e.g. rust/golang etc.
I agree though that in the very early days layout was hard with CSS, but then in the very early days we didn't even have devtools and XMLHttpRequests were still something mysterious and exotic. Times have changed and CSS has changed along with it. I'd recommend you try revisiting modern CSS if you have not already done so - you may be pleasantly surprised at how easy it is these days.

lazyjones#
> CSS Media queries allow you to trivially handle different mediums (screen size, pixel density, screen-vs-print etc). It really is very very easy.

Disagree. CSS media queries allow you to identify different media, just like uname(2) allows you to identify the platform you‘re running on. Handling all the aspect ratios, resolutions, capabilities, bugs, idiosyncracies of the current device or modus operandi is not at all trivial, especially if you don’t want to design for each situation from scratch.

nl#
Agree.

Worth noting that the real separation of content from presentation is JSON-data + a CSS/HTML hybrid front-end, often implemented as an off-the-shelf display framework (Bootstrap etc).

themacguffinman1 reply#
It's only a failure when viewed through the lens of application development.

The web platform wasn't initially designed for applications, it was designed for documents.
If you're crafting a document, you can separate style from content pretty neatly with CSS.

Mikhail_Edoshin#
What if my style requires a triple outline around a header?
lmm#
My heretical view is that it's time to abandon CSS. You already generate your HTML with some program (whether server-side or javascript) that takes a canonical, normalized representation of your content and spits out repetitive HTML elements (one pattern of elements for a button, another for a calendar, etc). Have that same program apply inline styles on elements that need styling.
Mikhail_Edoshin#
The straightforward way to separate content from presentation is to have a step that transforms that content into a specific form: 2D screen based, 2D page-based, aural, etc., including different purpose like a small read-only mobile gadget vs a full-screen desktop app. Web technologies actually have a beginning of this: XML source + XSLT processor, which is a general-purpose declarative tree transducer. But web community took a wrong turn here.
fulltrottle#
> The idea with CSS was that we would be able to separate content from presentation

I've been a frontend dev close to 5 years now, and recently I read the entire CSS spec front-to-back in scrutinizing detail for a project.
If the goal was really to decouple presentation and content then CSS has failed spectacularly. Having element selectors, attribute selectors, child and sibling selectors, very tightly couples the content with the layout. It also has the ability to affect content by inserting text nodes for example using the 'content' rule.
I'd say one big gotcha that trips up most people is not understanding when a style is valid or not. Certain styles are only valid for certain display types (see the CSS spec). Also look at the non-normative references on W3C for the default style sheet to see what default rules get applied to elements
To really fully keep content and presentation decoupled you have to stay away from those things and use something like css modules or similarly have a one-class-per-component rule.

jvvw#
The fundamental problem, I think, is that alignment is a key concept in design which isn't reflected well in CSS. The concepts of normal flow and the box model are almost at odds with wanting to align lots of different parts of a page. CSS Grid and Flexbox do help with this certainly but don't completely solve the problem.

Even disregarding mobile and tablets, I think it's also sometimes surprisingly quite hard sometimes to specify how fundamentally you want a page to look in differently-sized browsers - how things like spacing and guttering and so on should work particularly when your content is dynamic.
Plus, there is the fact that it is hard to shield parts of your page from being inadvertently affected by CSS that you don't want to affect it. Again, there are ways to minimise this, but if you're not the only person working on your codebase, good luck!
And if you want to learn a bit about design, The Non-Designer's Design Book by Robin Williams is a good starting point. It is a quick and engaging read and will certainly make you start to appreciate things like the differences between fonts.

dsherry2 replies#
I actually prefer coding CSS from scratch. Color schemes and making things look nice IS hard, for my previous and current projects I had to get feedback from friends, family, end users, graphic designers, etc. UX is hard, it's a different field than programming, but there is a method, research, and science behind it.

Here's a good resource for UX: https://goodui.org
And here is one for color theory: https://uxplanet.org/color-theory-brief-guide-for-designers-...

devmunchies2 replies#
I also really enjoy building CSS UIs from scratch, but editing existing stylesheets is a pain point. Band-aid after band-aid.

I think keeping UI components tiny and coupling the stylesheets with the component is the best way I've seen (not necessarily styled components, just styles in the same folder as the component.)
As the component is removed, its easy to nuke the stylesheet with surgically removing related styles and not breaking something else.

monkpit1 reply#
Why not styled components? It’s what immediately jumped to my mind while reading your comment, until you said otherwise :)
arvinsim#
Styled components, CSS-in-JS and CSS modules largely solve the same problem. I think it's just a matter of preference.
hycaria#
>I also really enjoy building CSS UIs from scratch, but editing existing stylesheets is a pain point. Band-aid after band-aid.

I feel the same. I fiddled with css on personal projects just fine, but in my job, diving into years of accumulated, imbricated classes is a nightmare and even though I try, 80% of the time I end up passing the problem to the design team.

thirdsun#
Same here. I recommend to avoid bloated kitchen sink frameworks like Bootstrap and Foundation unless you don't plan to do any customizations at all and only include the parts you actually use. Otherwise you'll realize that you're actually fighting the framework by trying to override it.

Load more comments