【发布时间】:2015-08-06 16:10:46
【问题描述】:
我有以下标记:
<div class="heading-container">
<p class="stroke">Who we</p>
<h2 class="section-title extreme-bold">Contact us</h2>
<p class="stroke"></p>
</div>
现在我可以使用以下选择器选择第一个 .stroke:
.heading-container .stroke:nth-child(1){
max-width: 200px;
}
但以下不适用于第二笔画类:
.heading-container .stroke:nth-child(2){
max-width: 200px;
}
但以下再次有效:
.heading-container .stroke:nth-child(3){
max-width: 200px;
}
现在为什么值 3 对第二个 nth-child 选择有效?
对于第 2 个 nth-child 来说,followig 是否合适:
.heading-container .stroke:nth-child(2){
max-width: 200px;
}
【问题讨论】:
-
试试
.stroke:nth-of-type(2){ -
@Akshay 超级感谢!!!!!!
-
@Tenali 我看到那行代码正在工作?你能说说那行代码是如何解决你的问题的吗?
-
@Leothelion 见小提琴jsfiddle.net/kLr59ke6/2
-
@tenali 我检查了你的小提琴,仍然没有选择 h2 但下一个有红色背景..那么?
标签: css css-selectors