如何选择<li>作为锚元素直接父元素的元素?
在示例中,我的CSS将是这样的:
li < a.active {
property: value;
}
Run Code Online (Sandbox Code Playgroud)
显然有一些方法可以使用JavaScript来实现这一点,但我希望CSS Level 2本身存在某种解决方法.
我尝试设置样式的菜单正在由CMS喷出,因此我无法将活动元素移动到<li>元素...(除非我主题菜单创建模块,我宁愿不这样做).
有任何想法吗?
有没有办法可以从嵌套子中向父元素添加伪类. 仅使用CSS
示例:在.less文件中,这就是我所拥有的.
.collection {
// Some styling
.headingRow {
//Some styling
.heading{
//Some styling
// This is where i want it to add the styling for alternate .collection class
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我想要的输出
.collection:nth-of-type(2n+1) .headingRow .heading
{
background-color: #7a003d;
}
.collection:nth-of-type(2n) .headingRow .heading
{
background-color: #322f31;
}
Run Code Online (Sandbox Code Playgroud)
这就是我尝试的 - &从.heading类添加,我可以使用类似的东西添加父元素或类
.collection {
// Some styling
.headingRow {
//Some styling
.heading{
div&
// This results in div.collection .headingRow .heading { }
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法可以将Pseudo类添加到父祖先?