选择特定类的偶数和奇数子类 [英] Select even and odd childs of a particular class after a specific class child

查看:284
本文介绍了选择特定类的偶数和奇数子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML

HTML:

<div id="container">
  <div class="b">b7</div>
  <div class="b">b8</div>
  <div class="a">a1</div>
  <div class="b">b1</div>
  <div class="b">b2</div>
  <div class="b">b3</div>
  <div class="a">a2</div>
  <div class="a">a3</div>
  <div class="b">b4</div>
  <div class="b">b5</div>
  <div class="b">b6</div>
</div>

我想要类b之后的类b的奇数兄弟,即b1,b3,b4, b6(不应为b7)。
是否可以使用CSS?

I want odd siblings of class b which comes after class 'a' i.e b1, b3, b4, b6 (should not b7)are to be selected. is it possible using CSS?

推荐答案

检查小提示

.a+.b, .a+.b+.b+.b{
    background: red;
}

我使用相邻的兄弟字符。但是当 .b 计数更多时,此解决方案可能不可行。

I'm using adjacent sibling character. But this solution may not be feasible when the the .b count is more.

这篇关于选择特定类的偶数和奇数子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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