CSS3-在另一个元素之后选择元素 [英] CSS3 - select element after another element

查看:50
本文介绍了CSS3-在另一个元素之后选择元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS3是否可以选择一个接一个的元素?如果有,例如:

Is it possible with CSS3 to select an element that comes right after another? If I have, for example:

<div>
  <a class="a">One</a>
  <a class="b">Two</a>
  <a class="c">Three</a>
  <a class="b">Four</a>
</div>

我想选择仅在class ="a"锚之后的class ="b"锚.因此,我希望选择两个"锚,而不是四个"锚.

I want to select the class="b" anchor that comes after the class="a" anchor only. So I'd want the "Two" anchor selected and not the "Four" anchor.

在CSS3中可以吗?如果没有,在jQuery中有可能吗?(尽管,我更喜欢CSS).

Is that possible in CSS3? If not, is it possible in jQuery? (though, I'd prefer CSS).

推荐答案

您不需要CSS 3,在CSS 2.1中已经可以实现!:)

You don't need CSS 3 for this, it was already possible in CSS 2.1! :)

使用相邻的同级选择器 + :

.a + .b {
   /* styles */
}

这篇关于CSS3-在另一个元素之后选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆