[英]advanced CSS selector query based on the body class name
Can anyone suggest how I would go about creating a css rule that would vary depending on the body class? 谁能建议我如何创建一个根据身体类别而变化的css规则? This is within a backbone js app used within a mobile app.
这是在移动应用程序中使用的骨干js应用程序中。
At the moment I will have either 'ks3' or 'ks4' for a class on the body tag (as shown below) and i'd like to have .menu class for ks3 & one for ks4 目前,我在body标签上有一个类的“ ks3”或“ ks4”(如下所示),我想为ks3提供一个.menu类,为ks4提供一个
Current CSS : 当前的CSS:
.menu {
background-image:url(../img/navigation/bg-768x1024.png); // need to set to null if body class has ks4
background-size: cover;
color: #fff;
}
<body class="ks4">
<div class="stk">
<div class="shell">
<div class="menu">
<!-- my menu here-->
</div>
</div>
</div>
</body>
So in essence I am trying to do the following in psuedocode.. 因此,实质上,我正在尝试在psuedocode中执行以下操作。
if (body class is 'ks4') { use the existing .menu class but set background-image to none. if(body class is'ks4'){使用现有的.menu类,但将background-image设置为none。 }
}
Is this possible using advanced CSS selectors? 使用高级CSS选择器可以做到这一点吗?
Since you set a rule for .menu it applies to all elements with menu class. 由于您为.menu设置了规则,因此它适用于菜单类的所有元素。 Now all you need is to set a rule to override current rule for background image.
现在,您只需要设置一个规则以覆盖背景图像的当前规则即可。
body.ks4 .menu{
background-image:none !important;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.