html - CSS nth child - 在 href 中选择错误的 span 元素

标签 html css css-selectors

我正在尝试使用 CSS nth-child 选择器来设置 href 内的第三个 span 标签的样式,所以 href 是 parent 有效。它似乎不起作用,它要么为所有样式设置样式,要么根本不设置样式。

HTML 看起来像这样:

<div class="h3">
<span class="arr-bottom arrow-down chev-align">&nbsp;</span>
    <a href="#" class="">
        <span class="qFaq">First span</span>
        <span class="">Second span</span>
        <span class="faqChevron fa fa-chevron-down fl-right f">Third Span</span>
    </a>

CSS 看起来像这样:

 div.h3 > a:nth-of-type(3) > span {
    color:#999;
  }

我在这里设置了一个 JS Fiddle:http://jsfiddle.net/db1wsbbo/1/ .

最佳答案

您选择的是第三个 anchor 而不是第三个跨度。 http://jsfiddle.net/db1wsbbo/2/

.nth span:nth-child(3) {
  color: grey;
}
<div class="h3">
  <span class="arr-bottom arrow-down chev-align">&nbsp;</span>
  <a href="#" class="nth">
    <span class="qFaq">Q</span>
    <span class="">This is a span</span>
    <span class="faqChevron fa fa-chevron-down fl-right f">grey color</span>
  </a>
</div>

关于html - CSS nth child - 在 href 中选择错误的 span 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32122144/

相关文章:

javascript - Jquery 脚本有时只运行

jquery - 使用 jQuery 在 #wrapper 中获取 div 或 img 元素

html - 如何通过 css 类选择特定元素,而不是其他元素?

jquery - CSS 和 jQuery : . name vs name^= (即类 vs "id arrays")

css - 是否有 CSS 父级选择器?

javascript - jquery DataTable 搜索和排序不起作用

html - 使用(Excel)VBA 获取HTTP?

html - 如何从文档流中制作一行 <table>

css - 根据分辨率重新排列 Bootstrap 标记

jquery - 为什么我的easypie号码没有显示在里面?