我在 HTML5 上使用一些 CSS2 和 CSS3 选择器 标签,但似乎有一些(但不是全部)没有像我预期的那样工作。
这是一个可运行的例子:
/* Working as expected: */
div.wrapper p:first-child { color: red; }
div.wrapper p:nth-child(even) { color: fuchsia; }
/* NOT working as expected: */
div.wrapper article:nth-child(1) { color: blue; }
div.wrapper article:first-child { color: green; }
/* Working as expected: */
div.wrapper article:last-child { color: gold; }
P1, expected "color: red"
P2, expected "color: fuchsia"
P3, expected no css applied
P4, expected "color: fuchsia"
Article 1, expected "color: green" and/or "color: blue" ← not working as expected...
Article 2, expected "color: gold"
然后我的问题是:为什么 nth-child(n)
不会和 first-child
上的选择器标签有用吗?甚至更奇怪:
đứa con cuối cùng
选择器确实有效。我在 FF4、IE9 和 Chrome11 中测试,结果都是一样的。
标签起到健全性检查的作用;看到
nth-child(n)
选择器确实适用于某些标签。
我错过了什么?我的样本是否应该有效?
câu trả lời hay nhất
first-child
仅当标签是其父标签的第一个子标签时才选择该标签。在您的情况下,第一个 tag 是第五个标签。同样适用于
nth-child(n)
.它与同一类型的兄弟标签无关,而是与所有兄弟标签相关。来自 W3C:
The :nth-child(an+b) pseudo-class notation represents an element that has an+b-1 siblings before it in the document tree, for any positive integer or zero value of n, and has a parent element.
nguồn:http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
关于html - 未应用 HTML5 "article"标记上的第一个子项和第 n 个子项选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6256372/
我在获取列表项时遇到问题,下面是我的 hibernate 代码,在该代码之后是我的方法..下面是我的 junit 测试。我如何确保查询正确执行,以及如何检查结果是否实际工作..这个查询应该返回几个pi
我正在尝试填充对象 Point 3D 的 vector 。我的应用程序读取一个 csv 文件以通过三个坐标 x、y、z 加载 vector 。我使用 float 类型。这是我的代码。 main.cpp
如果我有一个 DataTemplate(或类似的东西),我可以在 Canvas 中使用非 UIElements 吗?我觉得我以前做过这个,这是可能的,但我想不通。这是一些代码...
何时调用类方法 fetchItems()而不是 getItems() ?有区别吗? fetchImage()对比 getImage()等等... 最佳答案 “获取”通常被认为是一个本地操作,只涉及戳内
我的数组中有多个项目,比如说超过 14 个项目。 如何以这种方式将它们分为 2 个不同的组:前 3 个(#1,2,3)将在数组 A 中,接下来的 4 个(#4,5,6,7)将在数组 B 中,下一个 3
这是我正在解决的问题: Assume that the developers of Myro are developing a new black box function called travel
有一个列表框,里面有一些项目。还有一个带有 3x3 矩阵的网格。用户将拖动一个项目并将其放在网格的一个单元格上。 我发现的大多数示例都是关于从一个列表框拖放到另一个列表框的。但我想放入一个网格单元格。
Tôi là một lập trình viên xuất sắc, rất giỏi!