24

LeSS in action

Embed Size (px)

Citation preview

Page 1: LeSS in action
Page 2: LeSS in action

LeSS in Action

[email protected]

Page 3: LeSS in action

What the …

• The dynamic stylesheet language

• LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions. LESS runs on both the client-side (IE 6+, Webkit, Firefox) and server-side, with Node.js.

Page 4: LeSS in action

Features

Page 5: LeSS in action

Variables

• @nice-blue: #5B83AD;

• @light-blue: @nice-blue + #111;

• #header { color: @light-blue; }

• @fnord: "I am fnord.";

• @var: 'fnord';

• content: @@var;

Page 6: LeSS in action

Mixins

• .border-radius (@radius) {

• border-radius: @radius;

• -moz-border-radius: @radius;

• -webkit-border-radius: @radius;

• }

• #header {

• .border-radius(4px);

• }

• .button {

• .border-radius(6px);

• }

Page 7: LeSS in action

Nesting

• #header {

• color: black;

• .navigation {

• font-size: 12px;

• }

• .logo {

• width: 300px;

• &:hover { text-decoration: none }

• }

• }

Page 8: LeSS in action

Operations

• @base: 5%;

• @filler: @base * 2;

• @other: @base + @filler;

• color: #888 / 4;

• background-color: @base-color + #111;

• height: 100% / 2 + @filler;

Page 9: LeSS in action

Color functions

• @base: #f04615;

• .class {

• color: saturate(@base, 5%);

• background-color:

lighten(spin(@base, 8), 25%);

• }

Page 10: LeSS in action

Namespaces

• #bundle {

• .button () {

• display: block;

• border: 1px solid black;

• background-color: grey;

• }

• .tab { ... }

• .citation { ... }

• }

• #header a {

• color: orange;

• #bundle > .button;

• }

Page 11: LeSS in action

Scope

• @var: red;

• #page {

• @var: white;

• #header {

• color: @var; // white

• }

• }

• #footer {

• color: @var; // red

• }

Page 12: LeSS in action

Importing

• @import "lib.less";

• @import "lib";

Page 13: LeSS in action

Escaping

• .class {

• filter:

~"progid:DXImageTransform.Micro

soft.AlphaImageLoader(src='imag

e.png')";

• }

Page 14: LeSS in action

Usage

Page 15: LeSS in action

Client-side

• Link your .less stylesheets with the rel set to “stylesheet/less”:

• <link rel="stylesheet/less" type="text/css"

href="styles.less">

• Then download less.js from the top of the page, and include it in the <head> element of your page, like so:

• <script src="less.js"

type="text/javascript"></script>

Page 16: LeSS in action

Server-side

• Once installed, you can invoke the compiler from node, as such:

• var less = require('less');

• less.render('.class { width: 1 + 1 }',

function (e, css) {

• console.log(css);

• });

Page 17: LeSS in action

Local CMD

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

• $ lessc styles.less

Page 18: LeSS in action

Practice

Page 19: LeSS in action

Overview

Page 20: LeSS in action

lib.less

Page 21: LeSS in action

example.less

Page 22: LeSS in action

More …

• Server-side dynamic compilation

• Server-side static deployment

• Client-side compilation with lazyload

• …

Page 23: LeSS in action

Reference

• http://www.lesscss.org/

Page 24: LeSS in action

Q & A & Thx