是否可以选择哪个孩子不是i
?选择没有我孩子的主播
例子:
<a href="#"> <!--select this-->
Link!
</a>
<a href="#"> <!--but not this-->
<i class="material-icons">menu</i>
</a>
我试图a:not(>i)
和a:empty
,但没有奏效。
是否可以选择哪个孩子不是i
?选择没有我孩子的主播
例子:
<a href="#"> <!--select this-->
Link!
</a>
<a href="#"> <!--but not this-->
<i class="material-icons">menu</i>
</a>
我试图a:not(>i)
和a:empty
,但没有奏效。
它,最遗憾的是没有。 It's been proposed,但就是这样。 你需要一些js。
var links = document.querySelectorAll("a"),
i = 0, ii = links.length;
for (i; i,ii; i++) {
if(!links[i].querySelector("i")){
links[i].classList.add("without-i");
}
}
定义2种样式。一个为a
,另一个为a i
。似乎没有其他方式,因为:not
不允许组合。
https://jsfiddle.net/rnu83ogm/1/
a{
color:red;
}
a i{
color:blue;
}
或用jQuery工作:
$("a:not(:has(>i))")
问题是,用这种方法,选定的元素将是'i'标签,而不是锚点。在我的情况下,我需要添加一个填充锚点,所以这是一个肯定的问题:( – Malork
对不起,马尔科:(无论是JS或做一些神奇的:'a:padding; a>我负面填充我':( –
我一直在寻找,就是这样,没有办法。谢谢你连接建议:) – Malork