How can I mixin a style that doesn't begin with a class or ID into another style?
[class*='col-'] {
float: left;
padding-right: 20px;
@media @medium{
padding-right: 0px;
}
}
.col-2-3 {
width: 66.66%;
[class*='col-']
}
How can I mixin a style that doesn't begin with a class or ID into another style?
[class*='col-'] {
float: left;
padding-right: 20px;
@media @medium{
padding-right: 0px;
}
}
.col-2-3 {
width: 66.66%;
[class*='col-']
}
It seems like there is no way to call such a mixin (one where there is only a attribute selectors without a preceding class or id selector) even in the latest version of the compiler. The below statement found in the Less website seems to imply that only those with class or id selectors are considered mixins.
You can mix-in class selectors and id selectors, e.g.
So, your best bet would be to use the extend
function which seems to work fine.
The below Less code which uses the extend
feature
[class*='col-'] {
float: left;
padding-right: 20px;
@media (min-width: 20px){
padding-right: 0px;
}
}
.col-2-3 {
width: 66.66%;
&:extend([class*='col-']);
}
produces the following output when compiled.
[class*='col-'],
.col-2-3 {
float: left;
padding-right: 20px;
}
@media (min-width: 20px) {
[class*='col-'],
.col-2-3 {
padding-right: 0px;
}
}
.col-2-3 {
width: 66.66%;
}
Using extend
is also more advantageous because it groups selectors and shortens the code.
If for whatever reasons you don't wish to use the extend
feature and limit yourself to only a mixin call then the only option is to write the common rules into a separate mixin (like in below snippet) and call it at both places.
.common-props(){
float: left;
padding-right: 20px;
@media (min-width: 20px){
padding-right: 0px;
}
}
[class*='col-'] {
.common-props();
}
.col-2-3 {
width: 66.66%;
.common-props();
}
Putting the common props within a mixin with parentheses would make sure that the mixin itself is not output in the compiled CSS.
I think your only option is two wrap the [class*='col-]
selector 'with a class' so that it can be mixed in.
.column {
[class*='col-'] {
float: left;
padding-right: 20px;
@media @medium{
padding-right: 0px;
}
}
}
.col-2-3 {
width: 66.66%;
.column;
}