Search posts, tags, users, and pages
Hey Lea! much thanks for doing this.
What's your take on the bad mouthing that CSS gets for being such a mess?
Do you think it's a must for all javascript developers to have good knowledge of CSS?
I do agree that a lot of it seems to be JS developers who are used to working imperatively (a series of commands) and cannot understand CSS due to its declarative nature. It's too different from what they know, and they're out of their comfort zone, so they're trying to bring it in it by moving everything to JS. For non-programmers, declarative languages are actually easier to deal with, because they don't have to care about ordering and state (e.g. compare :hover to mouseenter/mouseleave). This is why I think it's very important to be able to do things from CSS, without forcing everyone to learn JS: there are actually many people who are great at HTML & CSS and find JS hard or impssible. There are no official statistics on their exact number, but it appears that they are at least 50% of HTML/CSS authors. There is a recent movement to add JS APIs for things without a CSS counterpart because it's easier for browsers and "everyone knows JS anyway". I think we should fight this trend.
However I'm fully aware that CSS is a bit of a mess. I love it, kind of to how you love your best friends: they have some terrible habits, but they also have redeeming qualities, otherwise they wouldn't be your friends. CSS was originally designed for simple documents, not applications, and we're trying to make it something it was not designed for. However, we cannot change anything because we would break existing websites, so we are just adding and adding to it and it has become quite a messy, inconsistent pile of stuff. Even things we do realize were mistakes (e.g. margin: auto for centering, or border-radius instead of corner-radius) we can't fix because it would break websites.
Lastly, people have different performance expectations from CSS, which influences what is possible with the language. In JS the onus is on you not to create an infinite loop. In CSS, the language must actively prevent it. Therefore, there are many features that would simplify a ton of CSS tasks (e.g. element queries or referring to other properties), but because of the remote possibility of cycles, we cannot add them to the language. Also, even without cycles, if a feature cannot be implemented in a way that makes it blazing fast, it just doesn't get added to the language. Parent selectors are an example of this (yes, they are in Selectors 4, but will only be available in querySelectorAll).
All these issues result in CSS being incredibly confusing to work with, and only the first one is actually the author's fault. At work people often come to me with CSS problems that seem simple, so they blame their inability to solve them to their poor CSS knowledge. More often than not, it turns out that the simple thing they were trying to do is actually not possible without JS or markup changes. I always find it embarrassing when I have to tell them that.