Are there substantial differences between detached ruleset, e.g.
@detached-ruleset: {
@margin: 1px;
margin: @margin;
};
and non-parametric mixin? E.g.
.mixin() {
@margin: 1px;
margin: @margin;
}
Do they behave the same with nested operators?
The most obvious difference is syntactic (semicolon is mandatory for a ruleset), and the ruleset keeps its variables private, but that's all I could find. The manual doesn't go into details too much on that.
The detached ruleset is a variable. For variables in Less the last declaration wins and variables are lazy loaded.
For reusable code you can easily extend the .mixin() by defining a second mixin() with the same name:
.mixin() {
@margin: 1px;
margin: @margin;
}
.mixin() {
color: red;
}
When using a detached ruleset in the above you should repeat all propperties cause the second declaration overrides the first:
@detached-ruleset: {
@margin: 1px;
margin: @margin;
};
@detached-ruleset: {
@margin: 1px;
margin: @margin;
color: red;
};
See also: https://stackoverflow.com/a/30384948/1596547
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With