ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

CSS Less(ish)

by kizza ALL

Use variables and nesting in your css files with Sublime Text 2 & 3

Details

  • 2015.01.21.00.22.08
  • github.​com
  • github.​com
  • 9 years ago
  • 1 hour ago
  • 12 years ago

Installs

  • Total 169K
  • Win 159K
  • Mac 7K
  • Linux 3K
Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10
Windows 0 0 1 0 0 0 2 2 0 1 0 0 1 2 0 0 1 2 1 1 0 0 0 1 0 0 2 0 2 3 1 0 0 1 0 0 0 1 1 0 0 1 1 0 0 1
Mac 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

CSS Less(ish)

A Sublime Text 2 & 3 plugin that implements a stripped down version of the functionality in css preprocessors (such as LESS) so that you can use css variables and nesting without any effort.

CSS Variables

Store variables within comments using the “@” symbol, then use them anywhere within your css.

/* @link = #6699CC */  
a { color: @link; }

produces

a { color: #6699CC; }

CSS Nesting

Nest styles within other blocks to append that selector to all children.

header [
    h1 { color:blue }
    a { color:blue }
]

produces

header h1 { color:blue }
header a { color:blue }

CSS Colours

Use colour functions when declaring css variables including lighten, darken, saturate, and desaturate. You can pass existing variables as arguments too.

/* 
@base-colour = #336699
@link = lighten(@base-colour, 20%) 
*/  
a { color: @link; }

produces

a { color: #3d7ab7; }

CSS Functions

Several css shortcuts functions are available including transition, transform, box-shadow, and linear-gradient. (These reference http://caniuse.com for browser specific rules)

/* 
@transition   = transition(all 0.3s ease)
@transform    = transform(rotate(0.6deg))
@shadow       = box-shadow(0 0 0.4em #000)
@gradient     = linear-gradient(#fff, #ddd)
*/  
div { 
    @transition; 
    @transform;
    @shadow;
    @gradient;
}

produces

div { 
    -webkit-transition: all 0.3s ease;
            transition: all 0.3s ease;

    -webkit-transform: rotate(0.6deg);
        -ms-transform: rotate(0.6deg);
            transform: rotate(0.6deg);

    -webkit-box-shadow: 0 0 0.4em #000;
            box-shadow: 0 0 0.4em #000; 

    background-image: -webkit-linear-gradient(bottom, #fff, #ddd);
    background-image: linear-gradient(to top, #fff, #ddd);
}

CSS Maths

You can add and multiply numeric variables too (works with px, em or %)

/* 
@padding = 1em
@width = 10em + 2 * @padding
*/  
div { width: @width; }

produces

div { width: 12em; }

How does it work?

The plugin doesn't require any third party libraries or tools to be installed - in fact it's not really a css preprocessor at all.

When you save a css file using the features above the plugin instantly compiles down the output “pre save”, writes it to disk, then restores your original css (all without you seeing it).

Why?

CSS proprocessors are wonderfully powerful, but I wanted to be able to use the essential functionality they provide simply and without any effort. The other advantage is that when debugging, your css styles are traced back to the original source document (since your css smarts comes from the file itself rather than being compiled into a separate file)

Read More

You can read more on the wiki.