如何复合css选择器在一起 [英] how can I compound css selectors together
问题描述
是否可以使用带有第n个类型(1)选择器的:not()选择器?
is it possible to use a :not() selector with a :nth-of-type(1) selector?
我要选择没有标题something的第一个
i.e. I want to select the first
that doesn't have the title "something"
<html>
<head>
<style type="text/css">
p
{
color:#000000;
}
p:not([title=something]):nth-of-type(1)
{
color:#ff0000;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p title="something">This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
<div>This is some text in a div element.</div>
</body>
</html>
推荐答案
类型
在原始选择器( p
)上运行时,它不会对 p:not = something])
。
The nth-of-type
is acting on the original selector (p
), it's not acting on the result of p:not([title=something])
.
p:not([title=something]):nth-of-type(1)
这是说,找到< p& c> c> c> c> 这没有找到任何元素,因为第一
< p>
有标题something。
This is saying, find the <p>
without a title of "someting" that is also the 1st <p>
on the page. This doesn't find any elements as the 1st <p>
has the title "something".
你想要的是不包含标题something的第一个< p>
。我不知道CSS是否有很好的方法。
What you want is the 1st <p>
that doesn't contain the title "something". I don't know if CSS has a good way of doing that.
如果你愿意使用jQuery,你可以这样做:
If you're willing to use jQuery, you can use do this:
$('p:not([title="something"]):eq(0)')
或:
$('p').not('[title="something"]').eq(0)
这篇关于如何复合css选择器在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!