【发布时间】:2016-06-01 09:02:06
【问题描述】:
我有一个帖子网格,我正在尝试为 h2 标签之间的每个标题赋予不同的颜色(绿色、红色、蓝色 - 一遍又一遍的那种模式)。
html(简体)是这样的:
<div class="fusion-posts-container">
<div>
<div>
<div>
<ul>
<li>
<div>
<img>
<div>
<div>
<a></a>
<div></div>
<a></a>
<h4><a></a></h4>
<div>
<a></a>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
<div class="fusion-post-content-wrapper">
<div class="fusion-post-content post-content">
<h2 class="entry-title"><a>THIS TITLE</a></h2>
我已经尝试了几种方法,最接近定位该锚并更改其颜色的方法是:
.fusion-posts-container div:nth-child(3n+3) a{
color: #b7e352 !important;/*red*/
}
.fusion-posts-container div:nth-child(3n+1) a{
color: #fb5322 !important;/*green*/
}
.fusion-posts-container div:nth-child(3n+2) a{
color: #1592b0 !important;/*blue*/
}
但唯一有效的是红色,如果我同时使用它们,它会将最后一种颜色应用于所有标题。
我尝试了这个CSS: Can't get multiple :nth-child selectors to work,但没有成功,任何人都可以指出正确的方向吗?
【问题讨论】:
-
显示html结尾
标签: html css css-selectors