LESSCSS检查最近的父母是否有课程

时间:2014-12-16 10:46:09

标签: css less cascading css-preprocessor

我用:

.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 */}

我该怎么做?

1 个答案:

答案 0 :(得分:2)


首先,&标记引用当前的父选择器(如提到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 */}