组合:nth-​​of-type()和:not [英] Combining :nth-of-type() and :not

查看:262
本文介绍了组合:nth-​​of-type()和:not的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的情况试图结合两个伪类::not :nth-​​of-type()

I have a strange case of trying to combine two pseudoclasses: :not and :nth-of-type() to get rainbow striping on non-hidden items

有一个:not([selector]):nth-​​of-type ]),我假设css会先应用:not 项目,然后再应用:nth-​​of-type <

Having a :not([selector]):nth-of-type([rule]), I assumed css would filter the :not items first before applying the :nth-of-type rule, but having them in any order gives me the same result.

这里有一个jsfiddle演示了这个: http://jsfiddle.net/j7hjU/

Here's a jsfiddle that demonstrates this: http://jsfiddle.net/j7hjU/

我可能在做这些?

推荐答案


我假设css在应用之前先过滤:类型

I assumed css wouuld filter the :not items first before applying the :nth-of-type

不适用。 CSS是完全声明性的;每个选择器是一个独立于任何选择器部分的真或假的简单条件。这不是一个程序语言,你采取集和处理它,缩小每一步。具有过程规则的选择器语言将免于许多种优化,并且会更慢。

Nope. CSS is fully declarative; every selector is a simple condition that is true or false independently of any selector part. It's not a procedural language where you take a set and process it, narrowing it down with each step. A selector language with procedural rules would be immune to many kinds of optimisation and would be slower.

所以 nth-of-type 只是关于一个元素的父级中的位置,而不是在到目前为止的结果列表中的位置,因为CSS选择器没有这样的概念。选择器引擎可以在使用而不是缩小范围之前查找 nth-of-type 的测试不会相互干扰。

So nth-of-type is only about position within an element's parent, and not position in a 'results list so far' because CSS selectors have no such concept. A selector engine could look up the test for nth-of-type before narrowing it with not, as the rules do not interfere with each other.

这篇关于组合:nth-​​of-type()和:not的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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