You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CSS/JS实现:最后一个子元素无disabled类时为nth-last-child(3)设置样式

实现方案

你可以通过CSS :has() 伪类实现「最后一个子元素无disabled类时,为倒数第三个子元素设置样式」的需求,修改后的SCSS代码如下:

.VuePagination__pagination {
  // 判断最后一个子元素没有disabled类时,选中倒数第三个子元素
  &:has(.VuePagination__pagination-item:last-child:not(.disabled)) {
    .VuePagination__pagination-item:nth-last-child(3)::before {
      content: '..';
      position: absolute;
      right: 1px;
      top: 7px;
      font-size: 16px;
    }
  }
}

兼容性备选方案

如果需要兼容不支持:has()的低版本浏览器,可以用简单的JS逻辑实现:

const paginationList = document.querySelector('.VuePagination__pagination')
const lastItem = paginationList.lastElementChild
if (!lastItem.classList.contains('disabled')) {
  const targetItem = paginationList.querySelector('.VuePagination__pagination-item:nth-last-child(3)')
  targetItem.classList.add('show-ellipsis')
}

再对应添加CSS样式即可:

.VuePagination__pagination-item.show-ellipsis::before {
  content: '..';
  position: absolute;
  right: 1px;
  top: 7px;
  font-size: 16px;
}

内容的提问来源于stack exchange,提问作者bravo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 19:06:05