我有一个 jquery Accordion ,我想使用第 nth-child 为其分配奇数/偶数背景。
结构是这样的:
<div class="jobmenu accordion">
<a>
<section>
<article><img.....></article>
<article>Item 1 name</article>
<article>123</article>
</section>
</a>
<div>
<table class="itemTable">
<thead>...</thead>
<tbody>...</tbody>
</table>
</div>
<a>
<section>
<article><img.....></article>
<article>Item 2 name</article>
<article>432</article>
</section>
</a>
<div>
<table class="itemTable">
<thead>...</thead>
<tbody>...</tbody>
</table>
</div>
</div>
nth-child 在为 tbody 中的 trs 分配奇数和偶数值的表上完美工作,但我想对 Accordion 做同样的事情。这些文章都在为第 n 个 child 设置宽度的情况下正常工作,以使可折叠列表具有统一的外观,但每个“a”都分配给了奇怪的样式。除非我在 php 中物理地向它添加一个类,但这违背了干净的 css 设计的要点。
CSS 是:
.jobmenu a {
height:40px;
}
.jobmenu a:nth-child(even){
background: #CCC;
font-size: 12px;
display: block;
position: relative; /*To help in the anchoring of the ".statusicon" icon imageglossyback.gif*/
width: auto;
padding: 4px 0;
padding-left: 10px;
padding-right:10px;
text-decoration: none;
cursor:pointer;
}
.jobmenu a:nth-child(odd){
background: #999;
font-size: 12px;
display: block;
position: relative; /*To help in the anchoring of the ".statusicon" icon imageglossyback.gif*/
width: auto;
padding: 4px 0;
padding-left: 10px;
padding-right:10px;
text-decoration: none;
cursor:pointer;
}
.jobmenu article:nth-child(1)
{
width:350px; margin-left:15px; text-wrap:normal; float:left;
}
.jobmenu article:nth-child(2)
{
width:100px; float:left;
}
.jobmenu article:nth-child(3)
{
width:200px; float:left;
}
我假设这是因为 a 处于奇数位置而 div 处于偶数位置。有解决办法吗?
最佳答案
.jobmenu a:nth-child(4n+1){
/*style*/
}
我试过了,它有效。
关于jquery - 带有奇数/偶数行的 jquery Accordion 的第 n 个子问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9887759/