Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:56:24+00:00 2026-06-09T04:56:24+00:00

My less code is something like this: body { @var: white; &.blue { @var:

  • 0

My less code is something like this:

body {
  @var: white;

  &.blue { @var: blue; }
  &.red { @var: red; }
  &.abc { @var: #badass; }

  background-color: @var;
}

What I hope is, if the body has the class .abc the value of the variable @var is #badass, if you have the class .blue The value is blue and so on. But that’s not what happens, the value of the variable dont change independent of their remains classes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:56:25+00:00Added an answer on June 9, 2026 at 4:56 am

    You need to create a parametric mixin for that:

    .bg(@color){
      background-color:@color;
    }
    

    and then the following code will work:

    body {
      .bg("white");
    
      &.blue{ .bg("blue");  }
      &.red { .bg("red");   }
      &.abc { .bg(#bada55); }
    
    }
    

    What you are doing isn’t working, because you are reassigning the variable – which works perfectly, but not writing the new value to the class. (It would make absolutely no sense if LESS created new rules, every time you are just reassigning a variable.) Also, like any other programming language, LESS has scope, thus at the time it reaches background-color: @var; @var has the value white assigned to it and creates the rule accordingly. This following will work (but makes no sense of course):

    body {
      @var: white;
    
      &.blue{ @var: blue;    background-color: @var;}
      &.red { @var: red;     background-color: @var;}
      &.abc { @var: #bada55; background-color: @var;}
      background-color: @var;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, this is the example of LESS code .my_class{ color: #000; font: 12px/12px Arial;
I use C# code more-or-less like this to serialize an object to XML: XmlSerializer
I've got some inherited code that went something like this. (Please hold the laughter...
I'm fairly new to Lift/Scala but like the ideas of less code writing and
I have code that looks more or less like the code below but it
I recently saw some code from a college teacher where he had something like
In the Modern Objective-C runtime, you can do something like this: @interface MyClass :
I have this code: if (y == a && y == b && y
I would like to have something like this be generated from hbm2ddl: ______________ ______________
At the moment I have code to fade brightness adjustments which looks something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.