开发者

What are the advatanges of less?

http://less开发者_开发技巧css.org/

Yeah the language syntax looks cool, but are there any significant advantages?

Because from what I see there you actually write more CSS, and since the less stylesheet gets compiled by javascript you get a un-styled site for a few seconds...


That is if you use lesscss for client side sheet generation.

You can also use lesscss on the server side or even compile your sheets before hand.

For example, if you are using node.js you can generate your sheets on the server. Additionally, if you want, you can use it as a way to write more manageable templates and then "compile" your sheets to generate a formed style sheet for when you are reading for production.

I think it makes perferct sense, because it means that while you are in development, you can change a collection of colors in a single hex color change. When you are ready to deploy, you can compile before hand and then distribute that style sheet with your project.

Think about manageability and using the command line compiler.

Command Line

http://lesscss.org/

Less comes with a binary, which lets you invoke the compiler from the command-line, as such:

$ lessc styles.less

This will output the compiled CSS to stdout, you may then redirect it to a file of your choice:

$ lessc styles.less > styles.css

To output minified CSS, simply pass the -x option.


Why would you write more CSS using LESS? In the contrary, you write less. And the code that you write is way more verbose than normal css. You can create groups better, use inheritance... You just have a way better overview over your styling than you do with CSS.

My CSS-file for a project currently has over 800 lines... in LESS, it's just around 150.

And to the javascript-compiling: I generally use an offline compiler and upload just the compiled CSS, so I don't have to fuss with the JS client.


You can use a precompiler (ruby's got a cool one, got it running under win).

Try writing a site in less and you'll never want to get back to normal css again :) my own experience...


There is actually a LESS PHP compiler, which I use all the time. I think the best way to work out why it's better than CSS is to use it yourself, but I'll summarise some things:

  • If you have theme colours used all over the place, for example, and want to change them, it's very easy with LESS's variable system.
  • You actually write less markup than vanilla CSS, due to not having to retype long selector strings.
  • If you want to, say, use cross-browser rounded corners, the mixins reduce repetition to almost nothing; all you do is create a class with style definitions in it, and then simply "mix it in". Essentially it's a re-usable function. If you need to change something specific to all rounded corners elements, you just change the single function.
  • Yeah the language syntax looks cool Personally I think this is rather dismissive and ignorant; if you have a look around the LESS examples, you will see it is miles ahead of normal CSS in terms of usability and speed of development.

There are more reasons, but these should be enough to get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜