css - 选择类型的第一个 child

标签 css css-selectors

在此FIDDLE如果我有其他 child ,我该如何选择第一个 child ?

<div class="root">
  <div>5</div>
  <div class="child">1</div> // i want this one

</div>
<div class="root">

  <div class="child">2</div> 

</div>
<div class="root">

  <div class="child">3</div> 

</div>

我在下面尝试了这个 css 但它不起作用

.root:first-of-type  .child:first-of-type {
   color: red;
}

最佳答案

它会是:

.root:first-child .child:last-child {
   color: red;
}

https://jsfiddle.net/uLr6o99e/7/

关于css - 选择类型的第一个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29022318/

相关文章:

css - Bootstrap 无法与 meteor 一起正常工作

html - CSS 列表 ID 覆盖默认值

javascript - jquery 显示隐藏每个 div onclick

javascript - JQuery:点击除某些元素外的任何地方

css - 基于style属性应用CSS是不是不好的做法

javascript - 应用弹出消息框 OnClick

html - 将鼠标悬停在文本上以使用 CSS 更改大小

html - 选择除 ID 的 child 以外的所有类(class)

html - 将当前类添加到当前菜单项 CSS

html - 为什么:last-of-type not select the very last cell of a table?