Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Variables in Less

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 267
    Comment on it

    The one of the main feature of Less is the variables just like in a standard programming language. Variable can store any type of value colors, dimensions, selectors, font names, URLs etc. The use of less is to reuse the CSS syntax where ever possible.

    Here, we define two variables, one for background color and one for text color, both containing hexadecimal codes.

    @background-color: #ffffff;
    @text-color: #1A237E;
    
    h1{
      background-color: @background-color;
      color: @text-color;
      padding: 15px;
    }
    
    ul{
      background-color: @background-color;
    }
    
    li{
      color: @text-color;
    }
    

    Which converted to CSS looks like this:

    h1{
      background-color: #ffffff;
      color: #1A237E;
      padding: 15px;
    }
    
    ul{
      background-color: #ffffff;
    }
    
    li{
      color: #1A237E;
    }
    

    In this example, the background color is white, and the text is dark. If, we want to switch them around and have dark elements with white text, we can simply change the values of the variables, instead of manually replacing every css.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: