【问题标题】:How to get the next element after the .active class [duplicate]如何在.active类之后获取下一个元素[重复]
【发布时间】:2017-03-06 09:44:36
【问题描述】:

Trying to get next element after li.active class

我正在尝试使用 css 获取 .active 元素之后的下一个元素,获取 .active 类的元素是“Lightslider”的第一个列表项。

我试过下面的代码:

.lslide.active +  li:nth-child(1) {
  -ms-transform: scale(1.3);
  -webkit-transform: scale(1.3);
  transform: scale(1.3);
}

仅使用 CSS 是否可行?

谢谢。

【问题讨论】:

    标签: css class css-selectors listitem


    【解决方案1】:

    只需使用adjacent sibling selector +,您不需要nth-child 选择器:

    .active + li {
      color: red;
    }
    <ul>
      <li class="active">Item</li>
      <li>Item</li>
      <li>Item</li>
    </ul>

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 2019-11-17
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多