CSS3 - select element after another element

自闭症网瘾萝莉.ら 提交于 2021-02-08 10:56:22

问题


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>

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.

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


回答1:


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

Use the adjacent sibling selector + :

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


来源:https://stackoverflow.com/questions/18992849/css3-select-element-after-another-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!