7 ms·
Coding Horror: What's Wrong With CSS
- RyanMcGreal 17y agoIt makes sense for CSS to remain a static language and for the dynamic logic to stay in preprocessors like Sass and LessCSS, for the same reason that HTML itself is a static language for which the dynamic logic goes into preprocessors (PHP, Ruby, Python, etc.).
- treyp 17y agoyou don't necessarily have to duplicate code blocks all the time since you can declare a definition for multiple styles: .uno { color: green; font-size: 18px; text-align: center; } .dos { color: green; font-size: 18px; } can become .uno, .dos { color: green; font-size: 18px; } .uno { text-align: center; } also, as others have pointed out, nesting is kind of there in the form of a hierarchy. child elements will get parent styles for most properties.
- chriseppstein 17y agoSass provides inheritance to accomplish this same result but without spreading your selectors all over the place. .uno { @extend .dos; text-align: center; } .dos { color: green; font-size: 18px; }
- est 17y agoDoes anyone else think we would invent a whole new layout/typography system independent of HTML and CSS? I mean, HTML, .doc, .pdf , epub, etc. are all repeating themselves. The fact is the whole rich-text presentation stack need to be freshed and better designed for new HCI and new devices.
- robryan 17y agoWhile Jeff's issues with CSS are valid ones, the post feels like a lot of his, "here is a little bit about a few things both nothing really deep or helpful, click my ads now?". I guess it's a bit like his business partner Joel quitting blogging, hasn't got a great deal left to say.
- dpritchett 17y agoPart of being a high-output blogger is cranking something out even if it's not a revolutionary idea. I appreciated the post and I know where to go if I need deeper insights on LessCSS or SASS. Sometimes connecting the dots is all a blog post needs to do.
- petercooper 17y agoIt felt more like "Microsoft-land developer finally discovers technology most HN users have known about for ages" to me ;-)
- bruceboughton 17y agoThis is just Jeff's style. I'm not sure the fact he is a .NET developer is relevant. He likes to pump out vacuous link-baity articles. I don't particularly blame him though.
- petercooper 17y agoYou might be right. In contrast, Joel seems very clued up as to what's going on outside of his niche.
- robin_reala 17y agoMozilla recently added experimental support for -moz-any() which fixes (sort of) Jeff’s third pain point: http://dbaron.org/log/20100424-any http://dbaron.org/log/20100424-any
- rradu 17y agoCSS variables? Sign me up! (http://lesscss.org http://lesscss.org)
- marcusbooster 17y agoI haven't looked at this package, but it seems running the CSS through a preprocessor like m4 would achieve similar results - for those not into Ruby.
- pstuart 17y agoNoted in the comments of the article is that less is moving to JavaScript. http://github.com/cloudhead/less.js http://github.com/cloudhead/less.js
- juvenn 17y agoThat new node-based v2.0+ implementation can be 10x faster than the ruby-based implementation. # Ruby version $ time lessc -v lessc 1.2.21 real 0m1.681s user 0m1.492s sys 0m0.176s # Node.js version $ time lss -v lessc 2.0.0 (LESS Compiler) real 0m0.104s user 0m0.088s sys 0m0.016s Though it should be noted that Rubygems has introduced a bit overhead in the Ruby version.
- jamie_ca 17y agoI'm disappointed with this change - it seems like picking up the new shiny tech for the sake of new shiny tech, at the expense of usability. My mac came with ruby, but not node. Also, a 1.5-second speedup is not terribly compelling for something done rather infrequently (and if you're not caching or pre-processing to static files, you're doing it wrong).
- sjs 17y agoOne reason to move to JavaScript is so that you can process LESS on the server and client. This way you can serve up a static LESS file and let the user's browser parse it, cutting out the extra compilation step. But you can still compile it beforehand and serve up the CSS directly if you don't want or cannot afford the performance hit on the client. At the very least I could see myself using it in the browser for development.
- klochner 17y agoI'm not taking sides yet, but . . . "why CSS needs no variables" http://meiert.com/en/blog/20090401/why-css-needs-no-variables/ http://meiert.com/en/blog/20090401/why-css-needs-no-variable...
- r0s 17y agoMaybe I'm missing something here... The big problem with CSS without variables is the time and effort it takes to make changes. If you only have to change the declarations once, at the top of the file, well it doesn't get much easier.
- isleyaardvark 17y agoThere is not only no reason a preprocessor like SASS can't someday efficiently process selectors like he describes, but theoretically it would be easier with something like SASS. In SASS you could keep the color declaration alongside the other CSS declarations, then the preprocessor could simply find all the declarations with that variable and string them together with commas. Unfortunately the SASS preprocessor doesn't do that... yet. The main draw of SASS is the ease of development and maintainability, not reducing the byte size of your CSS files. Personally, I don't want to spend the time manually hunting through CSS to combine selectors in order to save a few bytes. To give you a more practical example, instead of a color like #efac68, imagine the variable held the value 1em or 10px. If you wanted to increase the width of the gutters between columns, it's easier to change $gutter than to try a find and replace of 10px in your CSS, while trying to only change the values you want.
- rradu 17y agoYeah, but if you can have a variable hold more than declarations than just a color value, then that's a lot of space saved.
- deleted 17y ago[deleted]
- gamache 17y agoI can't believe it; a screed against CSS constants, published on April 1st, and it claims not to be a joke.
- Xurinos 17y agoWhat is wrong with CSS is the same thing that is wrong with HTML and XML. We are trying to use these things as DSLs, but they lack a core aspect of a language: means of abstraction. As a result, modern website work generally involves using somebody's favorite layer on top of this web data that provides that missing aspect. Jeff's favorite ruby gem is one approach. I personally like the ideas behind languages the Lisp community is developing via Weblocks and UCW (on top of yaclml or cl-who) -- and the similar possibilities provided by perl's Catalyst::View::TD -- where you approach page design from the perspective of widgets combined on a page. Here is what is forced on us with this flat data approach: The server bears the weight of producing the flat data, and the network has the burden of carrying that large flat data from the server to the client. The client must render all that flat data. If the data had means of abstraction, the server would not need as many intermediate layers to convert it, the network would have less to transfer, and the client browser would be able to take advantage of optimizations for abstractions and parse less data. Has anyone made any real headway on getting a replacement for HTML browsing? a movement away from "pages" and more towards "gateways" or "portals" to the graphical net?
- nex3 17y agoInterestingly, Chris Eppstein, my co-developer on Sass, agrees with you that CSS needs abstraction. However, he concludes that Sass is a good language for expressing that abstraction: http://chriseppstein.github.com/blog/2009/09/20/why-stylesheet-abstraction-matters http://chriseppstein.github.com/blog/2009/09/20/why-styleshe...
- blasdel 17y agoWhy the hell do you want the web to use stateful, synchronous, persistent connections? Good luck implementing Xanadu.
- klochner 17y agohttp://en.wikipedia.org/wiki/XSL_Transformations http://en.wikipedia.org/wiki/XSL_Transformations
- Xurinos 17y ago
- deleted 17y ago[deleted]
- mtoledo 17y agoyou shouldn't declare your sass variable 'blue'. If it becomes green in the future, you'd have a 'blue = green' assignment. Even 'color1' would be a better name.
- krishna2 17y agoThe two things hard in computer science: cache invalidation and naming things.
- mscarborough 17y agoI'd say the latter is the more difficult. Nice point.
- isleyaardvark 17y agoYou should declare your sass variable 'blue', because it's easier to work with than #3bbfce. if you want to change it to green, you would change it in the declaration from border-color = !blue to border-color = !green. (Or add an intermediate variable like !primary_color = !blue.)
- petercooper 17y agoI think mtoledo's point is that variable names should have context, and not be mere appropriations of their content. For example, "theme_color" would be better than "blue" because you could use it in context among lots of different CSS definitions, and if your theme color changes, it's a single change, as opposed to changing all the "blue"s to "green"s or whatever.
- isleyaardvark 17y agoI understood that part, that's why I gave the example of !primary_color. The point I'm making is that naming a variable after a color isn't necessarily a bad thing and can be a useful abstraction, and there's no reason you can't do both. I can recognize some common color hex codes, but I find it easier to work with more human readable names. If I'm looking at a site and I want to make the orange color slightly darker, will I remember that it's !color3? Or is it easier to look through for !light_orange?
- deleted 17y ago[deleted]
- chewbranca 17y agoI'm in a similar situation, I've got a decent pool of apps running on the same framework that only differ in config and static files. The approach I took is using the ruby gem compass and sass. I moved any sass variables into a skin.sass file and that way each site can just implement its own skin file very easily with only editing a single file and not having to jump into the main css. This has made it relatively painless to create another skin for a new site. One issue I'm dealing with on this setup is that these skin files are site dependent and outside of the base code repo. They're in their own repo, but the issue is every site has its own files, so to add a new variable to the skin file requires adding it in 5-10 places, and that number is just going to get bigger. I'm curious if you guys have any suggestions.
- Legion 17y agoI am all about SASS. SASS feels like someone took CSS and decided to finish it.
- deleted 17y ago[deleted]
- evlapix 17y agoI can't be certain but I don't think that was meant literally This ubiquitous trifecta represents MVC almost perfectly.
- latch 17y agoFollowing @joehewitt recent thoughts on browser innovation, I think it would be cool if browsers added client-side support for processing lesscss (or sass) files. They could send an extra header (accept-encoding:less), and web servers could serve up main.css.less vs main.css.
- nex3 17y agoI disagree. One of the main benefits of CSS compilers like Sass and Less is that they can innovate at their own pace, without worrying about any browser compatibility headaches.
- sjs 17y agoThat's one reason why lesscss is being ported to JavaScript. http://github.com/cloudhead/less.js http://github.com/cloudhead/less.js
- mcantelon 17y agoSASS isn't new, but good that Atwood is pointing people to it. Much nicer than raw CSS.
- mace 17y agoWhen working on a web project where I have no designer I inevitably get sucked into hours of painfully tweaking CSS. The biggest pain points is that CSS is not programatic and feels very restrictive(it's a declarative non-turing-complete language); Nor is it concise.
- code_duck 17y agoI'm always out of the loop... I thought I was hip to be generating CSS with some glanky PHP compiler that I wrote.