css - 选择最后一个 :link from a nested dynamic navigation list

标签 css

我试图从一堆嵌套的无序列表中删除 a:link 的 :after 伪元素的内容。我似乎无法选择它。

如何为这个动态创建的导航列表选择最后一个 a:link?谢谢。

HTML

<nav class="site-nav children-links">

  <span class="parent-link">
    <a href="http://localhost/learnwebcode/index.php/sample-grandparent/">
      Sample grandparent
    </a>
  </span>

  <ul>
    <li class="page_item page-item-2 page_item_has_children current_page_item"><a href="http://localhost/learnwebcode/index.php/sample-grandparent/sample-page/" aria-current="page">Sample Parent Page</a>
    <ul class="children">
      <li class="page_item page-item-16">
        <a href="http://localhost/learnwebcode/index.php/sample-grandparent/sample-page/sample-child-one/">Sample child one</a>
      </li>
      <li class="page_item page-item-18">
        <a href="http://localhost/learnwebcode/index.php/sample-grandparent/sample-page/sample-child-two/">Sample child two</a>
      </li>
    </ul>
    </li>
  </ul>

</nav>

CSS

.children-links a:after {
  content: "➤";
}

.children-links ul:last-child li a:last-child:after {
  content: "";
}

最佳答案

根据给定的结构,您必须选择 .chidren ul 中的最后一个列表项。

anchor 链接始终是 li 的最后一个子元素,因此不需要任何额外的选择器。

.children-links ul.children li:last-child a:after {
  content: "";
}

关于css - 选择最后一个 :link from a nested dynamic navigation list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56146668/

相关文章:

javascript - 根据文本输入显示和隐藏 DOM 元素

javascript - 我应该如何区分引导响应导航栏中的下拉菜单

html - CSS 中媒体查询的奇怪行为。从其他语句继承属性值

html - 使用 :after psudeo selector? 清除 float

html - 如何将文本字段文本锚定到右侧?

jquery/css : how to implement a wipe left animation on background-color of a div

html - 如何让 div 元素内联显示?

html - 对齐 div 内容

html - Flexbox 高度增长问题

html - 具有背景中心的 Css h2 位置