The Constants Gardener
Published 19 years, 3 months pastThis news is a little musty, but Shaun Inman updated CSS-SSC recently. If you’re using CSS-SSC, you should definitely go grab the update.
“Hey, what’s CSS-SSC?” you exclaim? Oh, I’m sorry. It stands for Cascading Style Sheets Server-Side Constants. Here’s Shaun’s initial example:
@server constants { linkColor: #AB6666; linkColorHover: #710101; } a { color: linkColor; } a:hover { color: linkColorHover; }
In other words, you can define your own constants in CSS. This works because CSS-SSC is a preprocessor—it processes the style sheet before it’s sent to the browser, and turns it into something the browser can handle. (Put another way, what arrives at the browser is a regular style sheet, with none of the ‘SSC’ information.) Shaun offers more details in an earlier post. CSS-SSC requires you to have PHP hanging about, and also to edit some stuff on your server, like .htaccess files. You’ll also have to be careful about how you name your constants: use the constant name color, for example, and your CSS is going to go to a particularly mangled form of textual hell.
Personally, I’m both enthused and annoyed by CSS-SSC. I think it’s a great solution: definitely one of the best, lightest-weight, easiest approaches to adding preprocessing to CSS. I’m seriously considering putting it to use on ALA, in which I jumped through a few grouping hoops in order to get the fonts and colors just the way Jason wanted them. Dropping back to constants would make life a bit easier—and would also simplify the whole “per-issue coloration” feature. (Which I already have working, but via a large number of hoops, several of them on fire.)
I’m annoyed because it bothers me that Shaun had to create CSS-SSC in the first place. There have been occasional requests for constants in CSS. They get shot down every time. “Use a preprocessor!” is the cry, and at first glance, CSS-SSC would seem to give credence to that response. From my point of view, however, CSS should have had constants long ago, and what Shaun has done is proof.
The refusal to add constants as a feature of CSS has always stuck me as highly pointless. Over the past decade, many people have expressed a need for CSS constants in a number of fora, and it’s a good bet many more have had the need without publicly expressing it. Adding it to CSS would have done little to increase complexity on the implementor’s side; Shaun’s one-page PHP script (a good deal less when you remove the comments) proves that. Adding it to CSS would have meant authors could just do it, without having to install anything else first. Shaun’s made installation about as easy as it gets, but it’s still three or four steps more than should exist—and, for some authors, three or four impossible steps, due to their hosting situation. And if you aren’t running a local web server, then you can’t test your CSS-SSC-enhanced styles locally; they’ll have to go to a web server first.
Because CSS still lacks, and will apparently continue to lack, a way to define your own constants, I’m really glad Shaun has devised this low-threshold solution. I just wish that it hadn’t been necessary for him to do so in the first place.