Here’s a quick thought. Something I will try to incorporate more in my work with css.
I think the number one wish for css, is the introduction of variables. It is at least, a very common attribute in css frameworks suchs as LESS or Sass.
But the word “cascading” is in the acronym for a reason, and even though that doesn’t quite solve the lack of variables, it actually does take a pretty good shot at it.
Here’s an example of some pretty generic code:
h1 {
font-size: 200%;
color: green;
}
a:link, a:visited {
text-decoration: none;
color: green;
}
With the introduction of variables, it could look like this:
@contrastColor = green;
h1 {
font-size: 200%;
color: @contrastColor;
}
a:link, a:visited {
text-decoration: none;
color: @contrastColor;
}
This is good if we want to change the color green to another. We only have to change it one place. But this is, as I said, not possible without the use of one framework or another. So what can we do instead?
/* Contrast Color */
h1, a:link, a:visited { color: green; }
h1 {
font-size: 200%;
}
a:link, a:visited {
text-decoration: none;
}
As I said, this is something I will try to incorporate more in my style sheets, so I haven’t actually got any experience on it. But css is designed with this in mind (at least I’m guessing it is), so why try to fight the system instead of learning to play with with it? I imagine that on a large scale it can create very complex style sheets unless the code is rigorously commented and kept neat, but that’s not too scary. At least as long as you’re the only person working on the css.