I wish to nest a number of rules inside a parent css selector using Less CSS. Usually this works just fine, but I've encountered a construct in Twitter Bootstrap's css that's problematic. Here's the pattern in question as a mixin:
.responsive-invisibility() {
&,
tr&,
th&,
td& { display: none !important; }
}
Here's how I wish to use it:
body.force-sm-viewport-or-higher {
.visible-xs {
.responsive-invisibility();
}
/* more stuff */
}
Here's what this produces:
body.force-sm-viewport-or-higher .visible-xs,
trbody.force-sm-viewport-or-higher .visible-xs,
thbody.force-sm-viewport-or-higher .visible-xs,
tdbody.force-sm-viewport-or-higher .visible-xs {
display: none !important;
}
What I want:
body.force-sm-viewport-or-higher .visible-xs,
body.force-sm-viewport-or-higher tr.visible-xs,
body.force-sm-viewport-or-higher th.visible-xs,
body.force-sm-viewport-or-higher td.visible-xs {
display: none !important;
}
Is this possible without "expanding" manually the mixins inside a body.force-sm-viewport-or-higher
parent? Expanding the mixins would be very error-prone and tedious when upgrading Bootstrap.
NOTE
Here's where I found out what using the ampersand after a nested class name does: LESS CSS: abusing the & Operator when nesting?
EDIT 1
I also need to do the same thing with this mixin which is more complicated.
.responsive-visibility() {
display: block !important;
table& { display: table; }
tr& { display: table-row !important; }
th&,
td& { display: table-cell !important; }
}