H i,
Hoping you can help.
Is there a way for LESS to return just a value - feel like I'm missing something very obvious
Say I have:
@unit:em;
@basevalue:1;
Can I use something to give me a shorthand return for -
.someClass { padding: ~'@{basevalue}@{unit}'; }
Like say:
.returnUnit() { ~'@{basevalue}@{unit}'; }
.someClass { padding: returnUnit(); }
because what I'm ultimately hoping for is:
.returnUnit(@val) { @basevalue*@val@{unit}; }
.someClass { padding:returnUnit(0.5); }
Using a mixing I have to define the style property, however the value of this return function would be used for many different css properties.
Hope I made sense and I am just lacking deeper rtfm.
Many Thanks if you can.
Update as @Chococrocs pointer to the docs, thanks.
.average(@x, @y) {
@average: ((@x + @y) / 2);
}
div {
.average(16px, 50px); // "call" the mixin
padding: @average; // use its "return" value
}
- Looks like what I need ? - just seeing if I can always tag on the unit variable to it....
Update: That gets part way ...
.unitRelative(@val) {
@value : @basevalue*@val;
@relative: ~'@{value}@{unit}';
}
/* usage */
.someClass {
.unitRelative(2);
padding: @relative;
}
But not when
.someClass {
.unitRelative(2);
padding:@relative;
.unitRelative(3);
margin:@relative;
}
Is there another way ?