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 8355033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:44:16+00:00 2026-06-09T09:44:16+00:00

I understand LESS doesn’t have if/else structure and instead relies on guarded mixin statements.

  • 0

I understand LESS doesn’t have if/else structure and instead relies on guarded mixin statements. It doesn’t appear to be able to set a LESS CSS variable inside of a mixin though.

Anyone have an idea of how I could implement something to the effect of.

if( ispercentage( @height ) {
  @height: "1024px";
}

// Calculations dependent on @height
@textAreaHeight = 0.5 * @height;
@buttonHeight = 0.2 * @height;

I’ve looked at several other stackoverflow questions including:
LESS CSS – Setting variable within mixin

  • 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-09T09:44:19+00:00Added an answer on June 9, 2026 at 9:44 am

    Yes, it can be done. There was one bug that needed to be worked around.

    Example LESS Code

    //Set up guarded mixins
    .setHeight(@h) when (ispercentage(@h)) { 
       @height: 1024px;
    }
    
    .setHeight(@h) when not (ispercentage(@h)) { 
       @height: @h;
    }
    
    //set up main height
    @mainHeight: 50%;
    body { height: @mainHeight;}
    
    //call it by itself to make global
    //.setHeight(@mainHeight); <-this failed (appears to be a bug)
    .setHeight(50%); // <-this worked
    
    .subsection { height: @height; /* just to show it is setting it */}
    
    //use it for other globals
    @textAreaHeight: 0.5 * @height;
    @buttonHeight: 0.2 * @height;
    
    textarea { height: @textAreaHeight}
    button { height: @buttonHeight}
    
    //override it locally
    body.fixedHeight {
        .setHeight(300px);
        @textAreaHeight: 0.333 * @height;
        height: @height;
        textarea { height: @textAreaHeight}
    }
    

    Example CSS Output

    body {
      height: 50%;
    }
    .subsection {
      height: 1024px; /* just to show it is setting it */
    }
    textarea {
      height: 512px;
    }
    button {
      height: 204.8px;
    }
    body.fixedHeight {
      height: 300px;
    }
    body.fixedHeight textarea {
      height: 99.9px;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have more or less been able to understand and implement all these concepts
I understand that Javascript doesn't have multiple threads, but I'd like to know if
Google doesn't understand <> so that failed thus asking here. What does '<>' (less
Surveying work code (in a module called Surveyor, no less), trying to understand it.
I have a datatype that's more or less a character array. Each space in
I have found a few threads in regards to this issue. Most people appear
I mean I understand that these templates are aimed at designers and other less
I am trying to understand if I really have any case for using git/mercurial.
typedef boost::variant<long long,double,string> possibleTypes ; set<possibleTypes,less<possibleTypes> > ascSet ; set<possibleTypes,greater<possibleTypes> > descSet ; When
I've been researching this problem I have and I can't seem to understand it

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.