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

  • SEARCH
  • Home
  • 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 8276935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:32:10+00:00 2026-06-08T08:32:10+00:00

I want to create something like a themepicker. I use LESS.css. LESS.css has a

  • 0

I want to create something like a themepicker. I use LESS.css.

LESS.css has a variable which contains the main colors :

@colorOne: #222;
@colorTwo: #fff;
@darkGradientStart: lighten(@colorOne, 10%);
@darkGradientStop: lighten(@colorOne, 5%);
@lightGradientStart: @colorTwo;
@lightradientStop: darken(@colorTwo, 7%);

I want to change them if the tag has the color-class like this:

<body class='theme-blue'>

then I have written this in my less.css (after the default variables)

.theme-blue{
    @colorOne: blue;
}

but it still uses the default #222. It is not overwritten.

How can I solve this problem?

Thanks

  • 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-08T08:32:13+00:00Added an answer on June 8, 2026 at 8:32 am

    You cannot overwrite variables in LESS (within the same scope). The documentation specifically says:

    Note that variables in LESS are actually ‘constants’ in that they can only be defined once.

    For what you desire, you need to do a mixin:

    Example LESS Code

    .colorDefs(@c1: #222, @c2: #fff) {
        @colorOne: @c1;
        @colorTwo: @c2;
        @darkGradientStart: lighten(@colorOne, 10%);
        @darkGradientStop: lighten(@colorOne, 5%);
        @lightGradientStart: @colorTwo;
        @lightGradientStop: darken(@colorTwo, 7%);
    }
    
    .theme-blue {
        //import color definitions 
        .colorDefs(blue, yellow);
    
        // use them 
        color: @colorOne;
        background-color: @colorTwo;
    
        .gradient1 {
            background-image: linear-gradient(top, @darkGradientStart, @darkGradientStop);
        }
    
        .gradient1 {
            background-image: linear-gradient(top, @lightGradientStart, @lightGradientStop);
        }
    }
    
    
    .theme-green {
        //import different color definitions
        .colorDefs(green, red);
    
        // use them 
        color: @colorOne;
        background-color: @colorTwo;
    
        .gradient1 {
            background-image: linear-gradient(top, @darkGradientStart, @darkGradientStop);
        }
    
        .gradient1 {
            background-image: linear-gradient(top, @lightGradientStart, @lightGradientStop);
        }
    }
    

    Example CSS Output

    .theme-blue {
      color: #0000ff;
      background-color: #ffff00;
    }
    .theme-blue .gradient1 {
      background-image: linear-gradient(top, #3333ff, #1a1aff);
    }
    .theme-blue .gradient1 {
      background-image: linear-gradient(top, #ffff00, #dbdb00);
    }
    .theme-green {
      color: #008000;
      background-color: #ff0000;
    }
    .theme-green .gradient1 {
      background-image: linear-gradient(top, #00b300, #009a00);
    }
    .theme-green .gradient1 {
      background-image: linear-gradient(top, #ff0000, #db0000);
    }
    

    Solving 4K (i.e. a lot of) Lines of Code

    ed1nh0 commented about having 4K lines of code using the color variables, and not being able to “put that in a mixin.” Let me make a few comments on that:

    1. If 4K lines of code depend upon the body class to define the colors, then it is probably best to split each color into its own css file, and only load that file as needed (i.e. not grouping every code color into one file). This then calls into question whether you really want to be controlling color by body class.
    2. Regardless of whether one does what is recommended in 1., I believe one could still handle this with 4K of lines that use the colors. I believe the issue is not in using a mixin to define the color values themselves (i.e. not 4K lines of color variable definitions), but rather in the 4K lines of properties, classes, etc. that need repeating that are using the colors. But that repetition can be handled just as easily by wrapping it all in a mixin also. So my original answer above could be abstracted further to this (note that .colorDefs is the same as above and not repeated here):

    LESS

    .themeProperties() { // Imagine inside here the 4K lines of code
        // use them 
        color: @colorOne;
        background-color: @colorTwo;
    
        .gradient1 {
            background-image: linear-gradient(top, @darkGradientStart, @darkGradientStop);
        }
    
        .gradient1 {
            background-image: linear-gradient(top, @lightGradientStart, @lightGradientStop);
        }
    }
    
    .theme-blue {
        //import color definitions 
        .colorDefs(blue, yellow);
        .themeProperties(); //4K lines repeated here
    }
    
    .theme-green {
        //import different color definitions
        .colorDefs(green, red);
        .themeProperties(); //4K lines repeated here
    }
    

    The above does assume that there are not differences in how the variables are used by the properties, just what the values of those properties are. If there were any “differences,” then some tweaking mixins may need to be done for certain situations, but the concept should still hold.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create something like this: Main panel has its margins (x), and
I want to use DotNetOpenAuth to create something like this Is is authentication or
I want to create something like this. When the button clicks main form will
what to use for application planning/modeling? i want to create something like ... ClassName
I want to create something like smarty, but I don't want to use Smarty
i want create something like link_to which can link to request for permission in
I want to create something like a leaflet/magazine using Latex. Is it possible to
Is there a open source meme tracker ? I want to create something like
I want to try create something like Zend's Server Pagecache. What I want to
I want to do something like this create type Item as object ( id

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.