【发布时间】:2012-09-02 22:28:43
【问题描述】:
我这里是这样的:
<ul class="bwp-rc-ulist">
<li class="recent-comment">Item 1</li>
<li class="recent-comment">Item 2</li>
<li class="recent-comment">Item 3</li>
<li class="recent-comment">Item 4</li>
<li class="recent-comment">Item 5</li>
<li class="recent-comment">Item 6</li>
<li class="recent-comment">Item 7</li>
<li class="recent-comment">Item 8</li>
<li class="recent-comment">Item 9</li>
<li class="recent-comment">Item 10</li>
</ul>
我想添加以下 CSS 样式:
li.list1, li.list6 { background-color: red; }
li.list2, li.list7 { background-color: blue; }
li.list3, li.list8 { background-color: black; }
li.list4, li.list9 { background-color: yellow; }
li.list5, li.list10 { background-color: gray; }
不幸的是,我不能这样做,因为 UL 和 LI 是由 wordpress 插件动态创建的(更好的 Wordpress 评论和除外插件)。
我已经阅读了一些 nth-child thingy,但它并不能解决我的问题。也许有人可以告诉我正确的脚本是什么?
我也在寻找适用于 IE7-9、chrome 和 ff 的脚本。
非常感谢。
【问题讨论】:
-
为什么 nth-child 不工作?这似乎是最合适的解决方案。
-
@Anthony:“所有主流浏览器都支持 :nth-child() 选择器,IE8 和更早版本除外。” - w3schools.com/cssref/sel_nth-child.asp 编辑:这是一个 IE7/8 解决方案:stackoverflow.com/questions/8492121/ie8-nth-child-and-before
标签: javascript css html-lists