I’ve started using LESS css at work (using CfStatic to compile the files) and slowly converting existing css to use LESS. We’ve been using the blueprint css framework for a grid layout and applying LESS css to the grid css for blueprint urged me to blog about it - its just so darn neat.
For those not familiar with Blueprint, the idea is that it gives your layouts a pseudo set of columns; you define how wide your columns are, and the spacing between them, then speficy the number of columns your html elements span using classes named, ‘span-1’, ‘span-25’, etc. Fans of gestalt shift (my boss), like this a lot because it allows for trouble free alignment of otherwise unrelated html elements.
The basic part of the blueprint grid css file looks like this:
This is all fine and dandy and there are even tools out there to let you define the width of your columns and produce the css for you. However, using LESS css, we don’t need those generators; we can just define our column widths and spacing as variables and use mixins to work out the widths of the different size spans. Something like this: