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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:11:42+00:00 2026-06-08T01:11:42+00:00

Is there any way to pass one mixin or style’s declaration to another mixin

  • 0

Is there any way to pass one mixin or style’s declaration to another mixin as an input parameter?

Let’s take a look at an example with animation keyframes. Following is how we define keyframes in pure CSS:

@-moz-keyframes some-name
{
    from { color: red; }
    to { color: blue; }
}

@-webkit-keyframes some-name
{
    from { color: red; }
    to { color: blue; }
}

@keyframes some-name
{
    from { color: red; }
    to { color: blue; }
}

Idea is to simplify these declarations using mixins, so we can have something like following:

.keyframes(name, from, to)
{
    // here we need somehow to reproduce structure
    // that we have in an example above
}

// define one animation
.my-from() { color: red; }
.my-to() { color: blue; }
// the following won't work because you cannot pass mixin as a parameter
// in way I have here, so I am looking for a way to solve this problem
.keyframes('some-name', .my-from, .my-to);

// define another animation
.another-from() { font-size: 1em; }
.another-to() { font-size: 2em; }
.keyframes('another-name', .another-from, .another-to);

The system will have different modules that could be dynamically attached to application as well as removed. So, don’t suggest me to use @import because it’s not the case. Output CSS is dynamically compiled on-fly using information about modules and their own LESS styles as well as base LESS dependencies like mixins library and etc.

Note: it will work for me if you know a way to pass class definition instead of mixin. In an example above it would be .my-from instead of .my-from() and etc.

  • 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-08T01:11:44+00:00Added an answer on June 8, 2026 at 1:11 am

    UPDATED for LESS 1.7.0+ (WAY Simpler)

    We can do this far more directly now with the 1.7.0 update and the ability to create rulesets, and to use variables in setting @keyframes.

    Now we really can pass a mixin through a parameter by a ruleset, or we can pass in the property stings themselves. So consider this:

    LESS (using 1.7)

    .keyframes(@name, @from, @to) {
        @frames: {
            from { @from(); }
            to { @to(); }
        };
        @pre: -moz-keyframes;
        @-moz-keyframes @name
        {
           @frames();
        }
    
        @-webkit-keyframes @name
        {
           @frames();
        }
    
        @keyframes @name
        {
           @frames();
        }
    }
    
    .keyframes(testName, {color: red; .myMix(0);}, {color: blue; .myMix(1);});
    
    .myMix(@value) {opacity: @value;}
    

    Note that I am passing both a property setting and a mixin call, and my output is:

    CSS Output

    @-moz-keyframes testName {
      from {
        color: red;
        opacity: 0;
      }
      to {
        color: blue;
        opacity: 1;
      }
    }
    @-webkit-keyframes testName {
      from {
        color: red;
        opacity: 0;
      }
      to {
        color: blue;
        opacity: 1;
      }
    }
    @keyframes testName {
      from {
        color: red;
        opacity: 0;
      }
      to {
        color: blue;
        opacity: 1;
      }
    }
    

    Note how the rulesets are passed, in brackets {...}, and then called, via @from() and @to() (looking a lot like a mixin call). I’m using these passed rule sets to set another ruleset of @frames which is then itself called to fill the keyframes definitions.

    More Generically

    Here I pass a private mixin to another mixin and then call it from that other mixin:

    LESS

    .someMixin(@class; @expectedMixin) {
        .@{class} {
          @expectedMixin();
          .myPrivateMix(0.6);
          test: 1;
        }
    }
    
    .someMixin(newClass; {.myClass;});
    
    .myClass {
      .myPrivateMix(@value) {opacity: @value;}
    }
    

    CSS Output

    .newClass {
      opacity: 0.6;
      test: 1;
    }
    

    Kept the below for legacy info.

    Updated (added LESS 1.4.0+ support)

    Wow, this took some doing, but I think I have something you can work with. However, it does take some special defining of your mixins in your modules, specifically, using pattern matching. So…

    First, Define Your Module Mixins

    Note how the module mixins intended to be used in a specific future mixin are defined with the same mixin name, but with a different pattern name. This was key to making this work.

    // define one animation in a module
    .from(my-from){ color: red; }
    .to(my-to) { color: blue; }
    
    // define one animation in another module
    .from(another-from){ font-size: 1em; }
    .to(another-to) { font-size: 2em; }
    

    If you also want individual mixin names in the modules, you should be able to do this:

    // define one animation in a module
    .my-from(){ color: red; }
    .my-to() { color: blue; }
    
    .from(my-from){ .my-from() }
    .to(my-to) { .my-to() }   
    
    // define one animation in another module
    .another-from(){ font-size: 1em; }
    .another-to() { font-size: 2em; }
    
    .from(another-from){ .another-from() }
    .to(another-to) { .another-to() }
    

    This should allow one to call either the straight mixin .my-from() or, to make it variably accessible within later mixins that access the singular .from() mixin group through the pattern matching.

    Next, Define Your Mixin

    For your @keyframes example, that was extremely difficult. In fact, a stack overflow answer was vital to helping me solve an issue with applying the @name, which was not applying under normal LESS rules because of it following the @keyframes definition. The solution to apply the @name looks nasty, but it works. It does have the, perhaps, unfortunate necessity of also defining a selector string to play the animation by (because it uses that string to help build the last } of the keyframes). This naming limitation would only be true of css strings that begin with @ like @keyframes and probably @media.

    Further, because we have a standard mixin name used in our module files, we can access that consistently within our new mixin, while at the same time passing a variable in to select the proper variation of that mixin through a pattern match. So we get:

    LESS 1.3.3 or under

    // define mixin in mixin file
    
    .keyframes(@selector, @name, @from, @to) {
        @newline: `"\n"`; // Newline
        .setVendor(@pre, @post, @vendor) {
            (~"@{pre}@@{vendor}keyframes @{name} {@{newline}from") {
                .from(@from); 
            }    
            to  { 
                .to(@to);
            }
           .Local(){}
           .Local() when (@post=1) {
               (~"}@{newline}@{selector}") {
                  -moz-animation: @name;
                  -webkit-animation: @name;
                  -o-animation: @name;
                  -ms-animation: @name;
                  animation: @name;
               } 
           }    
           .Local;
        } 
        .setVendor(""            , 0,    "-moz-");
        .setVendor(~"}@{newline}", 0, "-webkit-");
        .setVendor(~"}@{newline}", 0,      "-o-");
        .setVendor(~"}@{newline}", 0,     "-ms-");
        .setVendor(~"}@{newline}", 1,         "");
    }
    

    LESS 1.4.0+

    .keyframes(@selector, @name, @from, @to) {
        @newline: `"\n"`; // Newline
        .setVendor(@pre, @post, @vendor) {
            @frames: ~"@{pre}@@{vendor}keyframes @{name} {@{newline}from";
            @{frames} {
                .from(@from); 
            }    
            to  { 
                .to(@to);
            }
           .Local(){}
           .Local() when (@post=1) {
               @animationSector: ~"}@{newline}@{selector}";
               @{animationSector} {
                  -moz-animation: @name;
                  -webkit-animation: @name;
                  -o-animation: @name;
                  -ms-animation: @name;
                  animation: @name;
               } 
           }    
           .Local;
        } 
        .setVendor(""            , 0,    "-moz-");
        .setVendor(~"}@{newline}", 0, "-webkit-");
        .setVendor(~"}@{newline}", 0,      "-o-");
        .setVendor(~"}@{newline}", 0,     "-ms-");
        .setVendor(~"}@{newline}", 1,         "");
    }
    

    Now Call Your Mixin

    You can give it your own name, and just pass the straight pattern (all are no dot [.] and no quotes) for the pattern matches on the module mixins, but don’t forget that you also need a selector string (which is quoted) to get the mixin to work right:

    .keyframes('.changeColor', some-name, my-from, my-to);
    .keyframes('.changeFontSize', another-name, another-from, another-to);
    

    Which Gives You the Desired Output

    @-moz-keyframes some-name {
    from {
      color: red;
    }
    to {
      color: blue;
    }
    }
    @-webkit-keyframes some-name {
    from {
      color: red;
    }
    to {
      color: blue;
    }
    }
    @-o-keyframes some-name {
    from {
      color: red;
    }
    to {
      color: blue;
    }
    }
    @-ms-keyframes some-name {
    from {
      color: red;
    }
    to {
      color: blue;
    }
    }
    @keyframes some-name {
    from {
      color: red;
    }
    to {
      color: blue;
    }
    }
    .changeColor {
      -moz-animation: some-name;
      -webkit-animation: some-name;
      -o-animation: some-name;
      -ms-animation: some-name;
      animation: some-name;
    }
    @-moz-keyframes another-name {
    from {
      font-size: 1em;
    }
    to {
      font-size: 2em;
    }
    }
    @-webkit-keyframes another-name {
    from {
      font-size: 1em;
    }
    to {
      font-size: 2em;
    }
    }
    @-o-keyframes another-name {
    from {
      font-size: 1em;
    }
    to {
      font-size: 2em;
    }
    }
    @-ms-keyframes another-name {
    from {
      font-size: 1em;
    }
    to {
      font-size: 2em;
    }
    }
    @keyframes another-name {
    from {
      font-size: 1em;
    }
    to {
      font-size: 2em;
    }
    }
    .changeFontSize {
      -moz-animation: another-name
      -webkit-animation: another-name;
      -o-animation: another-name;
      -ms-animation: another-name;
      animation: another-name;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to pass values between two forms. Let's say, I have
Is there any way to directly pass a variable number of arguments from one
Is there any way to pass HTTP AUTH username and password along with an
Is there any way to pass command line parameters to a Flash projector in
Is there any way to pass a callback to java code, from C. And
I am wondering if there is any way to pass in a value when
Other than querystring, is there any other way to pass a value with the
Is there any way that I can pass arguments in selector? example: I have
Is there any way in Notepad++ (or even with another tool) to change the
In ColdFusion, is there any way to pass in a struct of parameters to

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.