Generate variables with loops (“Shorter/friendly-named alias for a complex statement” problem)

后端 未结 1 1981
无人共我
无人共我 2020-12-11 23:15

I know that in LESS is possible to generate many CSS classes using loops. I personally used this technique to answer another user\'s question.

Now I\'m facing the fo

相关标签:
1条回答
  • 2020-12-11 23:59

    (Now when Less v3.x and higher provides native support for custom functions).

    Just as in most of other programming language, instead of a list of auto-generated/predefined variables, this programming problem is solved via function functionality. I.e. you define a function like:

    .transparent-black(@value) {
        return: fade(@nero, @value ./ 10);
    }
    

    And then instead of @transparent-black-* variable you simply use .transparent-black(*)[] function call, e.g.:

    div {
        color: .transparent-black(50)[];
    }
    

    This is obviously a simplified example (in a real project I certainly would make black/white/etc to be the function parameters too).

    0 讨论(0)
提交回复
热议问题