Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Less custom function/mixin

For example I have next less code

form.someForm
{
    .form-group
    {
        > div
        {
            @media @wideMobile
            {
                width: calc(~"100%-144px");            
            }
        }

        > label
        {
            @media @wideMobile
            {
                width: 138px;            
            }
        }

    }
}  

I want to write something like

form.someForm
{
    .setWidths(138px,144px); 
}

To get the same result. How can I do that?

like image 726
user1325696 Avatar asked Jun 10 '26 02:06

user1325696


1 Answers

I guess all those examples at the docs could emanate a few ideas:

form.someForm {
    .setWidths(138px, 144px);
}

// the mixin:

.setWidths(@labelWidth, @divMargin) {
    .form-group {
        > div {
            @media @wideMobile {
                width: calc(100% ~'-' @divMargin);
            }
        }

        > label {
            @media @wideMobile {
                width: @labelWidth;
            }
        }
    }
}

Or even shorter (if the descendants share same media query):

.setWidths(@labelWidth, @divMargin) {
    .form-group {
        @media @wideMobile {
            > div   {width: calc(100% ~'-' @divMargin)}
            > label {width: @labelWidth}
        }
    }
}
like image 160
seven-phases-max Avatar answered Jun 15 '26 15:06

seven-phases-max



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!