html - 如何使用 CSS 选择此 Div

标签 html css

<div class="one">
    <div> </div>
    <div class="three"> </div>
    <div class="four"> </div>

</div>
<div class="one">
    <div> </div>
    <div class="three"> </div>
    <div class="four"> </div>
</div>
<div class="one">
    <div> </div>
    <div> </div>
</div>

我想选择第四类的第一个 div,我不想选择第四类的任何其他 div,只选择第一个。

如何使用 CSS 实现这一点?

最佳答案

您可以简单地使用first-child 来做到这一点。你会调用你的类(class) + first-child 然后是 div。告诉它您只需要您调用的类的第一个实例。

one:first-child .four 表示您只想要第一个 one 类的 four 类。

这是一个例子:jsfiddle .

.one:first-child .four{
  /* Your code here...*/
}

关于html - 如何使用 CSS 选择此 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31730256/

相关文章:

javascript - 如何在 jQuery 的 hover() 事件的热点中包含元素的边距?

javascript - IE 特定的 CSS 不呈现

Java .split() 与正则表达式匹配 html <a> 链接

jquery - 将鼠标悬停在按钮上以获取模式框中的选项,例如 google plus

html - 视频作为 html 中的背景

javascript - Jquery - 在参数中选择一个数字字符串

html - 不需要的 margin

html - 为什么粉色框在IE6中不重叠?

css - 是否可以水平居中对齐一行加起来不等于 12 的 Bootstrap 跨度?

css - 我在一行中有 3 个 div,如何让中间的 div 保持精确的宽度,而随着屏幕尺寸变小,左右 div 缩小?