Live data from Hacker News

Ask HN: Is it just me, or is CSS too damn hard?

news.ycombinator.com

101–110 of 358 posts

Re: Ask HN: Is it just me, or is CSS too damn hard?

#101
I’ve been working with CSS for about 20 years now and it still baffles me at times. I understand selectors just fine and I’ve memorized most rules, but placement and spacing are still unintuitive in my opinion, not to mention all tbe browser-specific rules and overrides. Oh yeah and there are plenty of young devs who don’t understand that SCSS generates CSS and don’t understand actual CSS. It also doesn’t help that so many libraries and frameworks encapsulate all the CSS heavy-lifting for you, never forcing you to actually have to learn CSS, which is in fact hard.

Re: Ask HN: Is it just me, or is CSS too damn hard?

#102
post #76

Earlier quoted context omitted.

The sad thing is that by the 1990s we'd figured out how to do good UI design for desktops, but then we promptly forgot every single bit of that knowledge when the web came along.

In the mid-90‘s the web wasn’t that bad, people used normal buttons, unstyled links and basic tables. The downward spiral started when corporations came and wanted their “CI” styling, then designers came and wanted to be “creative” and turned web pages into minigames where you have to guess what color or text style denotes a link, what the icons mean and how to trick the infinitely-scrolling website into displaying t…

I have a lot of time messing with css that could have been solved in minutes using tables instead...

Re: Ask HN: Is it just me, or is CSS too damn hard?

#104
As somebody who has been writing CSS for 13 years and watched numerous people fail here is the deal.

You have to confront the challenges head on and solve for them directly. Unlike JavaScript there is no magic framework abstraction hide from your fears shortcut. You have to embrace this reality both cognitively and emotionally. This is the reality, accept it. If you cannot get past this barrier give up and do something else with your life.

That said CSS isn’t too hard but it takes some very real practice up front to wrap your mind around it. The browser tools are much better than they used to be.

First you have to understand that CSS describes markup and markup is a tree structure. A solid understanding of the DOM is helpful but not required. Most CSS properties cascade down to descendant DOM nodes but some do not, particularly anything addressing the box model.

Second you have to embrace the box model. Don’t use the box-sizing property to redefine reality. Embrace the box model and understand it deeply. It isn’t hard but needs to be seared into your brain so that you are thinking about it visually instead of as code properties. Once you have mastered comfort with the box model you can use box-sizing if you want, but you probably won’t.

Third, understand dimensions. For learning I recommend not using pixels. Set the body to font-size: 10px and use em units for everything else. This simplifies things by setting 1em to 10px for initial definitions and forces you to consider how the cascading works when 1em becomes some multiplicative value. You are already an experienced developer so the math won’t be hard. You just need to wrap your mind around why the value changes how to correct for it in the code.

Fourth, learn float. Float Changes an element into something like display:inline-block and allows content to flow around it. Specify clear:both on another element to stop the flowing/wrapping behavior. You can create columns by creating a parent element filled with floating children. Add a final child element with display:block and clear:both to limit the floating behavior to the parent.

Fifth, understand position. Default is position static. Avoid value absolute unless you deliberately want to impose layering and completely remove the element from the flow control of the page. The properties top, right, bottom, and left refer back to the last positioned ancestor node.

Finally, play with pseudo classes to be familiar with what’s available.

Practice those things and build up your confidence. It gets easy but it takes some effort. It is a different skill than programming logic. After I had first started learning there was something called the CSS Zen Garden that made for some practice. Here was my attempt: http://mailmarkup.org/zen/

Browsers evolve in how they render text, but when I made that Zen Garden thing all the text columns were in complete vertical alignment cross browser.

Re: Ask HN: Is it just me, or is CSS too damn hard?

#105
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.

Re: Ask HN: Is it just me, or is CSS too damn hard?

#106

Earlier quoted context omitted.

A layout engine and design are two entirely different concepts. CSS has nothing to do with design. It is the tool used to implement the design and there are loads of other layout tools out there that don't have CSS's infuriating quirks. On the flip side, they usually have steep learning curves because they are strict. For a long time, until less than a decade ago, designers knew nothing about CSS. They'd do a design…

> Some (unlucky) programmers entire job was turning PSDs into HTML and CSS. That was my entry into programming many years ago. But I wouldn't call it unlucky - early web devs like me (we didn't really call ourselves programmers back then) had front-row seats at the beginning of a revolution, and it certainly was entertaining to watch and be part of. > CSS has nothing to do with design CSS works the way it does becaus…

> CSS works the way it does because it was created to make the kind of designs that designers wanted possible

Well, not originally. Later that became a thing, yes - but all the design that was already there at that point (circa CSS 2) remained, as did the overall approach with cascading styles.

A styling language designed for HTML5 today from scratch, accommodating modern use cases, would likely look a lot different.

Re: Ask HN: Is it just me, or is CSS too damn hard?

#107
> I have no idea which colors "go" with which ones, and pretty much all fonts look like the same for me.

Can't help on the fonts thing here, but for colors, there are a couple of things to consider. You can use color wheels of different kinds to find matching colors and harmonious color palettes to create/use in a color scheme. There are many online sites that provide this for free. While deciding on colors, you should also consider accessibility from the color blindness point of view and the contrast point of view.

Re: Ask HN: Is it just me, or is CSS too damn hard?

#108
Your frontend experience sounds like you've only dealt with web apps. Try making more web sites. That is, collections of pages that have enough content on them to scroll. Don't use any framework, don't even use JS if you can help it -- maybe something like PHP is ok to avoid some repetition (i.e. just use it for require_once of shared html). Then you'll understand the environment CSS was forged in. Ctrl+F the comments here for "box model" for the main "make it click" piece. (Edit: you might even want to try designing without CSS, to see what that's like. It's actually not that bad, and may well remind you of how things are typically done in frameworks these days -- a regression IMO, but a reminder that separation of design from markup isn't truly necessary.)

Re: Ask HN: Is it just me, or is CSS too damn hard?

#109
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.

Re: Ask HN: Is it just me, or is CSS too damn hard?

#110

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…

> 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.

Post reply on HN