I'm trying to understand why this nth-of-type selector isn't working as expected. My goal is to make the first .row element red, and all others after the first blue, while leaving the items in green as they are.

我试着理解为什么这个nof类型的选择器不能像预期的那样工作。我的目标是使第一个。row元素红色,所有其他元素在第一个蓝色之后,同时保留绿色的项。

https://jsfiddle.net/darrengates/pa34zyjd/14/

https://jsfiddle.net/darrengates/pa34zyjd/14/

.wrapper div {
  width: 200px;
  background-color: green;
  color: white;
  margin: 5px;
  padding: 5px;
}
.wrapper .row:nth-of-type(n+1) {
  background-color: red;
}
.wrapper .row:nth-of-type(n+2) {
  background-color: blue;
}
<div class="wrapper">
  <div class="option">option</div>
  <div class="button">some button</div>
  <div class="row">I wanna be red</div>
  <div class="row">I wanna be blue</div>
  <div class="row">I wanna be blue</div>
  <!-- all other row elements after the first should be blue -->
</div>

更多相关文章

  1. 怎么动态设置html的canvas元素的尺寸?
  2. JQuery基于元素的高度添加类
  3. 单个元素html上的多个类
  4. 样式通常以相同的组合出现:创建单个类还是组合元素?
  5. 在href元素中使用标记<c:out [duplicate]
  6. CSS3列 - 添加第二个元素后的额外宽度
  7. 垂直对齐div中的两个元素
  8. 如何用c#获取服务器端元素的innerhtml(内部有另一个服务器端控件)
  9. 如何让你的前端代码更像HTML5(用语义元素构造html5)

随机推荐

  1. 【Android】Activity知识点
  2. android GridView 去掉自带点击边框效果
  3. ImageView、Bitmap的属性android:scaleTy
  4. Android_VectorDrawable矢量图与SVG
  5. Edittext 取消长按 复制和粘糊等操作
  6. Android_查看linux内核版本和android文件
  7. OpenMax
  8. android中的menu和子menu小结
  9. Android中使用sqlite笔记
  10. android中控件的遮盖问题