NOTE: This post describes a library which has been discontinued. These days I use SASS instead.
Scaffold CSS was developed by Anthony Short and it is every CSS-coder’s dream come true:
Variables, nested selectors, abstractions from vendor-specific properties etc. etc. etc. Good stuff!
Installation and usage couldn’t be simpler! (Really. I don’t see how it could!)
You place the library folder in whatever folder holds you CSS-files. Then you copy-paste the .htaccess-file that redirects every request for your CSS-files to the library. Scaffold then reads through your CSS and interprets whatever tricks you’ve written and serves up nicely formatted (or minifed, if you prefer) W3C-compliant CSS.
”What’s this good for?”, you say?
Well. Consider this piece of regular CSS:
form#searchbox #arrival_date,
form#searchbox #departure_date,
form#searchbox #persons,
form#searchbox #location
{
font-size: 18px;
color: white;
margin-bottom: 20px;
}
form#searchbox #arrival_date label,
form#searchbox #departure_date label,
form#searchbox #persons label,
form#searchbox #location label
{
width: 100px;
display: inline-block;
}
form#searchbox #arrival_date input,
form#searchbox #departure_date input,
form#searchbox #persons input,
form#searchbox #location input
{
font-size: 18px;
width: 180px;
height: 40px;
padding-left: 10px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
behavior: url("boxsizing.htc");
}
form#searchbox #arrival_date .popupcalendar_icon,
form#searchbox #departure_date .popupcalendar_icon,
form#searchbox #persons .popupcalendar_icon,
form#searchbox #location .popupcalendar_icon
{
background: url(./graphics/images/sprites.png) no-repeat 0 0;
height: 295px;
width: 314px;
display: block;
text-indent: -9999px;
overflow: hidden;
background-position: -271px -20px;
height: 39px;
width: 31px;
zoom: 1;
display: inline;
display: -moz-inline-box;
display: inline-block;
vertical-align: top;
margin: 3px 0px 0px 10px;
}
Even though it’s nicely ordered and very readable, this code is still quite hard to understand at first look. You can’t just read what’s going on. What’s related to what? You need to look back and forth a few times to see this.
This makes it bad code!
Good code is always easy to read and understand.
Now look at the same code in Scaffold syntax:
@constants {
labelTextColor: white;
gutter: 10px;
}
form#searchbox {
#arrival_date, #departure_date, #persons, #location {
font-size: 18px;
color: !labelTextColor;
margin-bottom: #[2 * !gutter]px;
label {
width: #[10 * !gutter]px;
+inline-block();
}
input {
font-size: 18px;
width: 180px;
height: #[4 * !gutter]px;
padding-left: #[1 * !gutter]px;
+border-box();
}
.popupcalendar_icon {
image-replace: url('./graphics/images/sprites.png');
background-position: -271px -20px;
height:39px;
width: 31px;
+inline-block();
margin: 3px 0px 0px 10px;
}
}
}
The nesting immedietaly makes the code easy to read!
The selectors come in a logical order. The code is scannable, and in my opinion this is quite a revolution as far as CSS goes!
And it gets even better!
As you may have noticed, my second code example is full of non-CSS properties.
These are Scaffold-specific functions, constants and ”mixins”.
For example: A standard gutter width of 10px is defined as a constant, then used throughout the style declarations by reference.
No more search-and-replace for simple color changes!
This feature alone will save me countless hours.
Then there’s stuff like ”+inline-block();” or ”+border-box();”. These are ”mixins” that basically call a set of CSS properties that take care of crossbrowser compatibility. Scaffold serves up vendor-specific properties and even a selection of IE-behaviors, filters and expressions to get the desired effect working all around. Now we have a one line trick that’ll fix box model-quirks or get inline-blocks behave like expected. (Or rotation, shadows and other CSS3-goodies for that matter). This means more time for coffee, which is nice!
Finally we have functions like ”image-replace: url(‘./graphics/images/sprites.png’);”
This line takes care of everything regarding CSS image replacement. It even automatically sets the correct height and width fitting the specified image file.
The library has tons of useful features and some pretty advanced ones too. Everything is cached, so it’s just as fast as regular CSS.
So if you’re lucky enough to have your CSS-files served from an Apache server with PHP enabled, then by all means, do not miss out on Scaffold CSS!
