LESS CSS - 在嵌套类中从dom树向上访问类 [英] LESS CSS - accessing classes further up the dom tree from within a nested class

查看:254
本文介绍了LESS CSS - 在嵌套类中从dom树向上访问类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要使用LESS CSS从嵌套类中进一步访问dom树,请参阅示例:

I want to be able to access classes further up the dom tree from within a nested class using LESS CSS, see example:

HTML:

<html class="svg">
 <body>
  <div class="content">
    <div class="container">
      <div class="logo"></div>
    </div>
 </body>
</html>

LESS:

.container {
  .logo {
      background:url(/images/ws-logo.gif);
  }
}

我要定位html上的.svg类标记从.logo嵌套规则中,保持整洁,而不是编写另一个规则像这样:

I want to target the .svg class on the html tag from within the .logo nested rule, to keep things tidy instead of writing another rule like this:

.svg { 
  .container {
    .logo {
        background:url(/images/logo.svg);
    }
  }
}

 .container {
    .logo {
        background:url(/images/logo.gif);

        (some-symbol).svg {
           background:url(/images/svg-logo.svg);
        }
    }
 }



我使用modernizr检测svg支持。

I'm using modernizr to detect svg support.

任何人都知道这是否可能?或有任何建议?

Anyone know if this is possible? Or have any recommendations?

推荐答案

是的! (更新)



当我测试此这里时,它工作!

    .container { 
        .logo { 
            background:url(/images/logo.gif);
            .svg & {
                background:url(/images/svg-logo.svg);
            } 
        } 
    }

这篇关于LESS CSS - 在嵌套类中从dom树向上访问类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆