Giter Club home page Giter Club logo

simpledropdown's Introduction

#LESS is more

  1. Nested Selectors
  2. Mixins
  3. Functions
  4. Colours

##LESS nests selectors

nav {
    width: 100%;
    height: 50px;
    float: left;
    ul {
        width: 100%;
        height: 100%;
        li {
            float: left
            width: 20%;
            margin: 10px 30px;
            &:first-child {
                margin: 0;
            }
            > a {
                width: auto;
                text-align: center;
            }
        }
    }
}

Becomes:

nav {
    width: 100%;
    height: 50px;
    float: left;
}
nav ul {
    width: 100%;
    height: 100%;
}
nav ul li {
    float: left
    width: 20%;
    margin: 10px 30px;
}
nav ul li:first-child {
    margin: 0;
}
nav ul li > a {
    width: auto;
    text-align: center;
}

##Mixins

.box-sizing () {
    -webkit-box-sizing: border-box;
    -moz-box-sizing:    border-box;
    box-sizing:         border-box;
}

.box {
    width: 20%;
    padding: 5px;
    .box-sizing.
}

Outputs:

.box {
    width: 20%;
    padding: 5px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing:    border-box;
    box-sizing:         border-box;
}

They can also take in variables

.gradient(@start, @finish) {
    background-color: @start;
    background-image: -webkit-linear-gradient(top, @start, @finish);
    background-image:    -moz-linear-gradient(top, @start, @finish);
    background-image:     -ms-linear-gradient(top, @start, @finish);
    background-image:      -o-linear-gradient(top, @start, @finish);
    background-image:         linear-gradient(to bottom, @start, @finish);
}

header {
    .gradient(#333,#000);
}
body {
    .gradient(#000,#333);
}

Outputs:

header {
    background-color: #333333;
    background-image: -webkit-linear-gradient(top, #333333, #000000);
    background-image:    -moz-linear-gradient(top, #333333, #000000);
    background-image:     -ms-linear-gradient(top, #333333, #000000);
    background-image:      -o-linear-gradient(top, #333333, #000000);
    background-image:         linear-gradient(to bottom, #333333, #000000);
}
body {
    background-color: #000000;
    background-image: -webkit-linear-gradient(top, #000000, #333333);
    background-image:    -moz-linear-gradient(top, #000000, #333333);
    background-image:     -ms-linear-gradient(top, #000000, #333333);
    background-image:      -o-linear-gradient(top, #000000, #333333);
    background-image:         linear-gradient(to bottom, #000000, #333333);
}

Can have defaults:

.box-sizing (@type: border-box) {
    -webkit-box-sizing: @type;
    -moz-box-sizing:    @type;
    box-sizing:         @type;
}

.box {
    width: 20%;
    padding: 5px;
    .box-sizing.
}

Outputs:

.box {
    width: 20%;
    padding: 5px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing:    border-box;
    box-sizing:         border-box;
}

##Functions

Can have mixins based on criteria:

.set-bg-color (@text-color) when (lightness(@text-color) >= 50%) { 
  background: black;
}
.set-bg-color (@text-color) when (lightness(@text-color) < 50%) { 
  background: #ccc;
}

body {
    color: #333;
    .set-bg-color(#333);
}

##Colours

LESS also has functions that work specifically with numbers.

###darken()

@color: #FFF;
body {
    background-color: darken(@color, 20%);
}

###lighten()

@color: #3F3F3F;
body {
    background-color: lighten(@color, 20%);
    color: darken(@color, 20%);
}

simpledropdown's People

Watchers

James Cloos avatar Luke Woollett avatar

Forkers

magicbill

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.