简体   繁体   English

嵌套规则更少-我可以将级联选择器放在主选择器之前吗?

[英]Less nested rules - can i put the cascaded selector before the main selector?

My selector needs to be: 我的选择器必须是:

 .tooltip.right .tooltip-arrow 

So I use the following nested rule: 因此,我使用以下嵌套规则:

.tooltip-arrow {

    .tooltip.right {
        left: -(@ttArrowSize - 5);
        margin-top: -@ttArrowSize;
        border-width: @ttArrowSize @ttArrowSize @ttArrowSize 0;
        border-right-color: @ttColor;
    }
}

But after compiling the selector looks like: 但是编译后,选择器看起来像:

.tooltip-arrow .tooltip.right

The main question is if I can indicate LESS to put the "cascaded" selector before the main one. 主要的问题是,我是否可以指示较少将“级联”选择器放在主要选择器之前。 Any workarounds are welcome as well. 任何变通办法也欢迎。

You can use the ampersand selector, which refers to the parent selector inside a nested selector. 您可以使用&符选择器,它引用嵌套选择器中的父选择器。

Interesting Article 有趣的文章

So this in LESS 所以这在较少

.tooltip-arrow {    
    .tooltip.right & {
            color:red;
    }      
    .tooltip.left & {
            color:blue;
    }
}

compiles to this in CSS 在CSS中对此进行编译

.tooltip.right .tooltip-arrow {
  color: red;
}
.tooltip.left .tooltip-arrow {
  color: blue;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM