I'm trying to make a LESS mixin that will give me this output:
.resource:nth-child(8n+1) { clear: left; }
I've got this so far:
.wrap-every(@n) {
&:nth-child(@n + "n+1") { // parse error on this line
clear: left;
}
}
.resource {
.wrap-every(8);
}
But it's giving a parse error on the indicated line
ParseError: Unrecognised input
Is there a way to do this?
Definition and Usage The :nth-child(n) selector matches every element that is the nth child of its parent. n can be a number, a keyword (odd or even), or a formula (like an + b). Tip: Look at the :nth-of-type() selector to select the element that is the nth child, of the same type (tag name), of its parent.
Use the querySelector() method to get the nth child of an element, e.g. document. querySelector('#parent :nth-child(3)') . The :nth-child pseudo class returns the element that matches the provided position.
The syntax for selecting the first n number of elements is a bit counter-intuitive. You start with -n, plus the positive number of elements you want to select. For example, li:nth-child(-n+2) will select the first 2 li elements.
You can pass in a positive number as an argument to :nth-child() , which will select the one element whose index inside its parent matches the argument of :nth-child() . For example, li:nth-child(3) will select the list item with an index value 3; that is, it will select the third list item.
you could do something like this:
.wrap-every(@n) {
&:nth-child(@{n}n + 1) {
clear: left;
}
}
this should have the desired output. Without any hacks needed.
you can try simple string interpolation:
.wrap-every(@n) {
@t: ~":nth-child(@{n}n + 1)";
&@{t} {
clear: left;
}
}
and the output CSS in both cases should be something like this:
.resource:nth-child(8n + 1) {
clear: left;
}
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