我有几个div
元素,我想在div
其中替换另一组样式。所以基本上将孩子的风格改变为交替的背景颜色,如下所示:
HTML
<article class="post"> <!--first post-->
<div class="title">Title Here</div>
content here
</article>
<article class="post"> <!--second post-->
<div class="title">Title Here</div>
content here
</article>
CSS
div.title:nth-of-type(even) {
background-color: #F00;
}
div.title:nth-of-type(odd) {
background-color:#00F;
}
有没有办法做到这一点,因为我知道使用css
替代样式它必须在父级中。或者如果没有jquery
,我可以使用任何脚本吗?
谢谢你。