Tags:
I think Bert is dead wrong. His arguments seem to boil down to "They make CSS too complicated and difficult to read". Huh? Nothing is harder to maintain or read than a CSS file with the same three colors repeated 20 times :-/
It would be very nice to have your colors and fonts declared in one place. DRY! You can handle some cases via inheritance and application of multiple classes to a single element, but it doesn't help when you want to use the same color for the foreground of one element and the background of another.
I think variables would be a huge help. A lot of the mess of CSS could be rectified that way.
The problem is, Bert's point boils down to programmers vs non-programmers. To a non-programmer, understanding the abstractions involved in using variables and other programming techniques is more costly than the benefits gained in DRYing out your CSS. To this, I agree.
Think of CSS like a product you are managing. CSS has two customer segments with a wide disparity in skills/understanding. If you implement variables and other programming abstractions, you run a high risk of undermining your other customer segment.
The abstraction represented by CSS variables is basically the same one introduced in 6th grade algebra. Anyone that didn't make it that far should probably avoid hand writing CSS and handling sharp objects. :-)
John said:I think variables would be a huge help. A lot of the mess of CSS could be rectified that way.
The problem is, Bert's point boils down to programmers vs non-programmers. To a non-programmer, understanding the abstractions involved in using variables and other programming techniques is more costly than the benefits gained in DRYing out your CSS. To this, I agree. Think of CSS like a product you are managing. CSS has two customer segments with a wide disparity in skills/understanding. If you implement variables and other programming abstractions, you run a high risk of undermining your other customer segment.
In my experience, this underestimates how difficult (and painful) it is for most non-programmers to learn programming.
Business is not like school. In business if you force your customers to do things that are too hard, they simply stop buying or using your product. Free markets force companies to be sensitive to the skills, talents and desires of their customers. Even if variables are 6th grade skills to you or you think it can be learned in 15 minutes, this is clearly not the case for the population at large (if it was, everyone would already know variables and this would not be an issue).
In my experience, this underestimates how difficult (and painful) it is for mosthow non-programmers to learn programming.
Business is not like school. In business if you force your customers to do things that are too hard, they simply stop buying or using your product. Free markets force companies to be sensitive to the skills, talents and desires of their customers. Even if variables are 6th grade skills to you or you think it can be learned in 15 minutes, this is clearly not the case for the population at large (if it was, everyone would already know variables and this would not be an issue).
Chris Runnells: I don't think that programming belongs in CSS, as that isn't it's purpose. It's easy enough to declare a single attribute for multiple elements, whether it's background color or setting the margins.
Chris Runnells: I'm not convinced by your argument. Colors are only used in a few places (IE: border color, background color, and font color).Colors are used in more than a few places. Borders alone have four colors, one for each side. I am currently working on a web theme system for an SNS platform where many of the colors are used in five or six attribute types within a theme. Having done a lot of work on Java Swing Look and Feel implementations and Flex skins I can say with certainty that this is very common in full featured theme / LaF implementations.
In an environment like you described, where you've got CSS for a large web application, it seems like the best idea would be to have a set of CSS that defines the structure of the design, but without any font or color information. Then you've got theme.css where you define colors, typography, background images, etc.Of course, but this in no way addresses the issue of CSS requiring values to be repeated if they are applied to different attribute types such as background and font color. We already use different style sheets for layout, color schemes, etc. This is an orthogonal concern.
body, hr, th, #header h1, { background-color: blue; }This is a contrived example because you rarely use default colors such as "blue" in a real world style sheet. Your blue is more likely to be something like rgb(5,12,247), repeated for your background-color and border.
table, .border { border: 1px solid blue; }
There's no reason why you can't contain all "decoration" to a single CSS file, and leave the structure of the content in a single unchanged file.Again, you are talking about the separation of structural and stylistic concerns which is important but completely orthogonal to the issue at hand.
Yes, DRY says you shouldn't repeat yourself, but I think setting up a single CSS file (or worse, multiple CSS files) where you've replaced all instances of a single color with a variable, you're not going to save yourself any time in the long run.Untrue. If you are dealing with a system with dozens of themes, each containing multiple style sheets containing dozens of colors you are saving yourself a lot of time and more importantly, you are creating a more maintainable system.
Sure, you might have saved a few bytes of data, but is it really worth the extra effort?Saving bytes is not the issue and yes, it is well worth the effort.
© 2025 Created by Daniel Leuck. Powered by