css - :nth-child related only to specific class or element

标签 css css-selectors

可以仅将 :nth-child 分配给特定元素,而不计算中间的其他元素(例如 http://jsfiddle.net/MgC4v/ 和 <*br>)。

<p>1</p>
<br>
<p>2</p>
<p>3</p>

p:nth-child(3) {
    background-color:red;
}

红线是第二条,不是第三条..谢谢

最佳答案

p:nth-of-type(3) {
    background-color:red;
}

仅选择第三个 <p>元素:),这是你的问题吗?

参见http://www.w3.org/wiki/CSS/Selectors/pseudo-classes/:nth-of-type 你的例子:http://codepen.io/anon/pen/DxGos

关于css - :nth-child related only to specific class or element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17773157/

相关文章:

html - 使用具有多个 id 的 H 选择器时如何缩短 CSS?

IE7 中的 CSS 属性选择器 - 包含样式属性上的子字符串

html - CSS 折叠/展开

javascript - 使用 CSS 将包含相关元素的 DIV 居中

javascript - "Rewind"模糊输入()

python - 如何使用 Selenium 和 Python 将文本发送到电子邮件字段

html - 如何划分我的 html 页面以显示带有 float 侧面板的 map 和标题栏

html - 为什么我的文字换行到第二行?

css - 应用于多个选择器的样式不适用于两者

html - CSS,选择 if :first-child has class ="selected"