LESS CSS examples

I’m using LESS in the new version that i’m developing of the framework ParaGRIDma.

To render the .less file in a .css i’ve choose the software WinLess. I also evaluate Simpless that is a more beautiful software to do the same task, but it give me some error editing the file. WinLess work like a charm.

Making loops in less

@iterator: 12;
.loop (@index) when (@index > 0) {
    .g-@{index}  { width: (100% *  @index / @iterator) }
    .loop(@index - 1); // next iteration
.loop (0) {} // exit loop
.loop (@iterator); // draw loop

Convering dimesions in less

Sometimes you want to change dimensions in your CSS. To do this you only need to add 0[unit]

@context = 12px;
@context/10 + 0em; // returns 1.2em;

Make color variations in less

You can convert given color by adding other color. For example:

@linkColor: #2a85e8;
@linkColorHover: (@linkColor + #111);

Importing files in less

If you want to import some other css file you can do it like:

@import "normalize.css";

If you want to process this CSS file like a LESS files do this:

@import (less) "normalize.css";

Nested rules in less

#header {
  h1 {
    font-size: 26px;
    font-weight: bold;
  p { font-size: 12px;
    a { text-decoration: none;
      &:hover { border-width: 1px }

Escribe una comentario