html - 使用 css 选择器 lastchild 和 :after together in angular2

标签 html css sass css-selectors

HTML:

<h2 class="title-main">
     <span class="title-inside">A</span>
     <span class="title-inside">B</span>
     <span class="title-inside">C</span>
     <span class="title-inside">D</span>
     <span class="title-inside">E</span>
     <span class="title-outside">F</span>
     <span class="title-outside">G</span>
</h2>

CSS:

:host/deep/.title-main {
    display: flex;
    margin-bottom: 0;

    .title-inside {
        &:after {
            content : '-';
        }
    }
}

我得到这样的输出

A-B-C-D-E-F G

我不想要最后一个 child 的 - 。我想要这样的输出

A-B-C-D-E F G

我尝试了很多选择。例如。其中一个我试过

title-inside:last-child ::after {
           content: ''
    }

但这行不通。谁能帮帮我

最佳答案

使用 :not:nth-last-of-type()

.title-main {
  display: flex;
  margin-bottom: 0;
}

.title-inside:not(:nth-last-of-type(3))::after {
  content: '-';
}
<h2 class="title-main">
  <span class="title-inside">A</span>
  <span class="title-inside">B</span>
  <span class="title-inside">C</span>
  <span class="title-inside">D</span>
  <span class="title-inside">E</span>
  <span class="title-outside">F</span>
  <span class="title-outside">G</span>
</h2>

这是 SASS version

:host/deep/.title-main {
    display: flex;
    margin-bottom: 0;

    .title-inside {
        &:not(:nth-last-of-type(3)){
           &::after{
            content : '-';
           }
        }
    }
}

关于html - 使用 css 选择器 lastchild 和 :after together in angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43586221/

相关文章:

javascript - Rough.js 使用 requestAnimationFrame 进行抖动/晃动

html - 删除 Squarespace 上的默认页边距

css - 为什么我的 CSS 自定义样式表规则被覆盖并且未在 SAPUI5 中应用?

html - 加载页面时将所有移动设备的图像居中

javascript - 悬停在其他对象上时 CSS 显示跨度

css - 延迟动画属性可以覆盖现有的吗?

html - 计算用户在整个网站上的总点击次数并相应地更改背景

html - Flex - 图像约束

html - 为什么我的 css 没有应用?

jquery - CSS/jquery 将居中的 div 从居中位置移动到窗口的左上角