7 ms·
The problem with CSS is that it wasn't designed to solve a particular problems. Solutions to those problems came later with the tools that were haphazardly thro
by cletus 16y ago
The problem with CSS is that it wasn't designed to solve a particular problems. Solutions to those problems came later with the tools that were haphazardly thrown together.
Example: vertical centering in CSS is far harder than it should be [1]. Why doesn't "vertical-align: middle" just work for divs like it does for table cells? I'm sure there are reasons. They just aren't good reasons. What's more: why hasn't CSS3 fixed this? It's a longstanding problem.
CSS is littered with examples like this that just go to show there was (and still is) a disconnect between what the W3C is doing and the problems people actually have.
My other big problem with CSS is the "inheritance" model. For one, it shouldn't be called inheritance. It should be called "cascading" because that's what it is.
Inheritance at the class level would actually be useful (and is another glaring omission).
Layout, even with CSS3, is still far harder than it should be. The approach CSS should've taken is to to work through a whole bunch of layouts and figure out how they're implemented. If it's hard, CSS still has gaps to fill. Don't release a spec until those gaps are filled.
[1]: http://www.jakpsatweb.cz/css/css-vertical-center-solution.html http://www.jakpsatweb.cz/css/css-vertical-center-solution.ht...
- lwhi 16y agoI agree that CSS can be frustrating - but I think it's a bit harsh to state CSS has failed when so many people are able to successfully use it to create a huge range of layouts. People assume CSS should be easy and straightforward - but like most things, it takes a while to get to grips with. -- I think there are maybe two main problems with CSS. One, is that for a long time logic wasn't enough when it came to writing CSS markup. A large number of browser quirks meant that hacks and workarounds needed to be employed all the time. This is luckily changing .. modern browsers are thankfully much more coherent than their previous incarnations. However, this perceived lack of logically coherence - and the need for arcane knowledge - is obviously infuriating to most people starting out .. The solution has been to learn a handful of techniques - read a lot, and press on. While it's initially annoying, its not an insurmountable task. -- The second is that CSS requires a lot of diligence on the part of the developer. There are good ways of writing code. I've found the 'cascading' part of CSS is quite often forgotten about - but well written mark-up can use this to greatly simplify the complexity of spaghetti code. -- "Example: vertical centering in CSS is far harder than it should be [1]. Why doesn't "vertical-align: middle" just work for divs like it does for table cells? I'm sure there are reasons. They just aren't good reasons. What's more: why hasn't CSS3 fixed this? It's a longstanding problem." I agree - this is annoying. However, HTML was designed to allow content to be viewed at various sizes - and to scale width-wise (allowing the vertical height to adapt automatically) - I've a feeling this might be part of the reason why vertical align hasn't been included). Vertically centring fixed height elements is very straightforward .. vertically alignment for dynamic height elements is less straightforward, but it's usually possible. -- "My other big problem with CSS is the "inheritance" model. For one, it shouldn't be called inheritance. It should be called "cascading" because that's what it is." The first C in CSS is there for a reason ;) I think the cascading feature is actually quite powerful. One of the things I'd most like is a way to use variables in CSS - but this will thankfully be addressed in CSS3. -- "Inheritance at the class level would actually be useful (and is another glaring omission)". Classes can be combined, and once applied, a class affects the descending elements contained in the DOM. I'm not sure what you'd ideally like? -- Lastly there are some good projects out there that address quite a few of the gaps in the CSS specifications in a very reasonable way. LESS[1] and SASS[2] are two that come to mind. [1] http://lesscss.org/ http://lesscss.org/ [2] http://sass-lang.com/ http://sass-lang.com/
- ericb 16y ago[3] http://en.wikipedia.org/wiki/Stockholm_syndrome http://en.wikipedia.org/wiki/Stockholm_syndrome
- lwhi 16y agoBut I honestly believe sometimes a bad workman blames his tools. I took the time to learn how to use it, so maybe I'm biased - but it's really not that bad.
- Travis 16y agoAnd sometimes tools are just bad. Yes, a bad workman blames his tools, but that doesn't mean all tools are as good as they can be. Sometimes a good workman blames his bad tools; when there aren't better alternatives, what can he do? Let me put my CSS thoughts in context: I self-assess to be about as competent in CSS as I am in PHP. Now, I know PHP isn't great. But when I'm smash-my-head-against-the-wall frustrated, it's usually because of CSS issues. >75% of the time. In general, I expect frontend layout work to be less frustrating than backend work. It's less complex, IMO. And, actually, it can be -- just by using tables for layouts. So it's not inherent complexity that causes the frustration, it's the CSS issue (tables remove that frustration for me). In short, I've returned to table based layouts because that tool fits my needs much much better than CSS. I use CSS for my styling, but layout goes into tables.
- lwhi 16y agoMaybe you should concentrate on back-end development? I can sympathise, but I really don't think reverting to table-based layouts is a good solution. EDIT: Reverting to table-based layouts _ISN'T_ a good solution.
- Travis 16y agolwhi - sure, I'm more comfortable doing back end dev work (and try to focus on it). But that doesn't change my opinion that CSS is a half assed solution that doesn't solve my problems. Tables do. And the counter-arguments against using a table based structure all tap into situations that haven't affected my specific context. So tell me again why I should use CSS based layouts? For me, they frustrate me and prohibit me from accomplishing my tasks. Tables don't do this. And all the downside to using tables? Not particularly relevant for my goals.
- masklinn 16y ago> My other big problem with CSS is the "inheritance" model. For one, it shouldn't be called inheritance. It should be called "cascading" because that's what it is. Cascading already means something in CSS (hint: the C means "Cascading", that quite strongly suggest there is a concept of cascade in it). And I'd like to see what problem you have with CSS inheritance: if an element inherits a property, then it gets the same (computed) property as its parent. That seems pretty simple and straightforward, and a good match for the word "inheritance". > Inheritance at the class level would actually be useful (and is another glaring omission). What does that even mean? Do you mean mixins at the block level? Overriding rules? Classes are just a type of selectors in CSS, where would inheritance fit in anything? And if you can inherit classes (whatever that's supposed to mean) why couldn't you inherit ids, attribute selectors or pseudo-selectors?
- lwhi 16y agoExactly - I don't think it's fair to blame a spec when its lack of knowledge that's driving the criticism. EDIT: Thinking about it - maybe the author should have employed a front-end developer? There's a good reason people specifically work on this stuff ..
- mkn 16y agoThere's a good reason people specifically work on this stuff .. I don't get this at all. Central to the design of HTML and the Web is the notion of democratic access to information and the ability for non-specialists to create it. Furthermore, the motivation behind CSS was to make it easier to do this work by separating the design from the information. CSS should therefore be, if not intuitive, at least easy to learn, use, and troubleshoot. It's true, we need brain surgeons to do brain surgery, but we shouldn't need specialists to do basic things like vertical centering, convincing layout without tables, and overriding styles in nested elements. We've come a long way from the intent of CSS if we're arguing that only specialists should use it.
- lwhi 16y ago"Central to the design of HTML and the Web is the notion of democratic access to information and the ability for non-specialists to create it." I imagine the large majority of the hackernews readership can be defined as a 'web specialist' of one kind or another, so if this were true most of us would be out of a job :P My point is - there's no good reason why front-end development should be any less complicated than back-end development. Just because people expect it to be easy, isn't a good enough reason ..