我用:

.first{
    .second{
        .third{
            .between_second_and_third & {
                /* some rules */
            }
        }
    }
}


最后我有:

.between_second_and_third .first .second .third {/* some rules */}


但是我想要:

.first .second .between_second_and_third .third {/* some rules */}


我该怎么做?

最佳答案

首先,&标记引用当前的父选择器(如here所述)

这就是为什么您得到此最终声明的原因,因为您定义了以下内容:

.first{
    .second{
        .third{
            .between_second_and_third .first .second .third {
                /* some rules */
            }
        }
  }


您只需将between_second_and_third类嵌套在... .second.third类声明之间,如下所示:

.first{
    /* first rules */
    .second{
       /* rules for second */
       .between_second_and_third {
          /* rules between */
          .third{
           /* some other rules */
        }
    }
}


此声明呈现以下CSS代码行:

.first { /* first rules */ }
.first .second { /* rules for second */ }
.first .second .between_second_and_third {/* rules between */}
.first .second .between_second_and_third .third {/* some other rules */}

关于css - LESSCSS检查最接近的 parent 是否上课,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27502808/

10-09 16:20