How LESS can make your life easier

How LESS can make your life easier

I’ve started using LESS a few months ago on a Tribune News projects. LESS allows you to extend the way you write CSS, letting you use variables, nested selectors, operations and mixins. It sounds great — and it is great — but there are a few things that can make it work against you. These are some of my thoughts on LESS.

What is LESS?

LESS — Leaner CSS — is, in the authors’ own words, a “new version of CSS” (better yet, of writing CSS), that is then compiled into “traditional” CSS using the LESS compiler.

There are 4 main things you can do with LESS that you can’t with normal CSS:

1. Variables

You can define a variable, such as “@text-color”, and use it throughout your stylesheet. If the colour of your text changes, you only need to change it once in your CSS — where the variable is initially defined.

2. Nested selectors

With nested selectors, instead of doing this and repeating yourself:

.top-story h1 { font-size: 24px; }
.top-story h2 { font-size: 18px; }

.top-story {
h1 { font-size: 24px; }
h2 { font-size: 18px; }
}

3. Operations

You can add, subtract, divide and multiply using operations. Here’s a quick example:

@content: 468px;
.top-story
{
width: @content;
}

4. Mixins

Mixins work a lot like variables, but you can specify a whole class in one. For example:

.b-radius {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.box {
.b-radius;
}

This is not a “how to” guide

The official LESS documentation is very clear on how to install it. I have to admit I usually stop reading instructions whenever “Terminal” is mentioned (and I know more people do), but I guess most CSS authors will be OK with it — if not, ask for help to your nearest web dev (or email me and I’ll give you the phone number of one).

After it’s installed, you’ll have two files: the .less file — this is the file you’ll be working with — and the compiled .css file.

There’s also LESS app, that makes it easier to use LESS. And I suppose that some CMS and servers let you use LESS directly, but the point of this article is not to teach anyone how to install it — it’s to go through its good and bad points.

Advertisement

About sarfarazhanfi

Over 10 years of hands-on experience in graphics and web designing, multimedia presentations. With two years of it management experience.Excellent knowledge of creative tools and techniques. Quick to grasp new ideas and concepts, and to develop innovative and creative solutions to problems. Able to work well on his own initiative and can demonstrate the high levels of motivation required to meet the tightest of deadlines. Even under significant pressure, possesses a strong ability to perform effectively

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.