.less is more

by DotNetNerd 8. December 2009 16:48

A little while ago I read about a nice little library called .less, which is a port from ruby less, that lets you write css, but with the added features of enabeling variables, operations, mixins and nesting. Today I decided to try it out, and I definately want to give it my recommendation.

Using variables makes stylesheets a lot more maintainable because it allows you to avoid having colorcodes scattered all around the stylesheet simply by writing:

@listbackground_color: #E3EFFF;

Nesting just makes it more maintainable and gives the stylesheet a better sence of structure like this:

table.MapsList
{
  background-color: @listbackground_color;       
  tr th
  {
    width: 300px;
    background-color: @listbackgroundheader_color;
  }
}

Finally mixins makes it possible to keep the stylesheets more DRY (don't repeat yourself) like so:

.rightBackground { background-repeat:no-repeat;background-position:right; }
th.headerSortUp { .rightBackground; background-image: url(desc.gif); }
th.headerSortDown { .rightBackground; background-image: url(asc.gif); }

An added bonus is that you can toggle caching and minimizing from your web.config.

 

Tags: ,

Comments (2) -

Jesper Blad Jensen
Jesper Blad Jensen Denmark
12/9/2009 6:21:21 AM #

Cool. I did not know that there was a .NET Version of Less.

I really like the idea of less. CSS should have been like that in the first place. That said, then i am really a sucker for syntax highlighting.
Do you know of any tool, that can highlight Less?

DotNetNerd
DotNetNerd
12/9/2009 6:59:37 AM #

Agreed. Regular css is really in need of better constructs, and .less hits the spot where it hurts the most.

I was actually fiddeling around trying to find something that would give me syntax highlighting yesterday, but I came up empty handed. Tell me if you bump into something, and Ill do the same by posting it here.

Who am I?

My name is Christian Holm Nielsen, and I work at Vertica A/S, in Denmark, where I build commerce and other custom solutions.

Some of my primary focus areas are code quality, programming languages and new technologies in .NET.

Month List