Conditional parameter validation in a LESS mixin function
-
14-07-2021 - |
Pergunta
How can I translate the following conditional to LESS?
.mixin(@width) {
width: (!@width ? auto : @width);
}
Results should be like:
[no value is passed]
LESS: .mixin();
CSS: width: auto;
[value is passed]
LESS: .mixin(200px);
CSS: width: 200px;
Solução
You can use default parameter values to accomplish this:
.mixin(@width: auto) {
width: @width;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow