【问题标题】:LESSCSS check if closest parent has classLESSCSS 检查最近的父母是否有班级
【发布时间】:2021-11-05 23:55:44
【问题描述】:

我用:

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

我该怎么做?

【问题讨论】:

    标签: css less


    【解决方案1】:

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

    【讨论】:

    • 因此,这是不可能的。好的。
    猜你喜欢
    • 1970-01-01
    • 2013-11-11
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多