Css 第n个子选择器

Css 第n个子选择器,css,less,css-selectors,Css,Less,Css Selectors,我的LESS是这样的 .img-preview { &:first-child:nth-last-child(6), &:first-child:nth-last-child(6) ~ a:nth-child(2), &:first-child:nth-last-child(6) ~ a:nth-child(3), &:first-child:nth-last-child(6) ~ a:nth-child(4), &:firs

我的LESS是这样的

.img-preview {
   &:first-child:nth-last-child(6),
   &:first-child:nth-last-child(6) ~ a:nth-child(2),
   &:first-child:nth-last-child(6) ~ a:nth-child(3),
   &:first-child:nth-last-child(6) ~ a:nth-child(4),
   &:first-child:nth-last-child(6) ~ a:nth-child(5) {}
}
如您所见,如果只有6个child,我将尝试选择最后一个元素的所有元素。除了像上面那样编写重复的代码,还有没有更好的方法来编写呢

我尝试了以下方法,但在编译时出现了错误

.img-preview {
       &:first-child:nth-last-child(6) ~ a:not(:last-child) {}
}
~a:not(:last child)
部分匹配第一个子元素之后的元素,因此不是第一个子元素本身。您仍然需要为以下内容选择
&:第一个孩子:第n个最后一个孩子(6)

.img-preview {
    &:first-child:nth-last-child(6),
    &:first-child:nth-last-child(6) ~ &:not(:last-child) {}
}

您只需要在您现在看到的内容之后添加一个大括号}。很抱歉,这是一个输入错误。虽然该选择器不是编写它的正确方法,但至少它应该编译时没有错误。