jquery - 带有奇数/偶数行的 jquery Accordion 的第 n 个子问题

标签 jquery css accordion css-selectors

我有一个 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/

相关文章:

jquery - 在无表 CSS 布局中实现 jqGrid

html - 使用显示属性时如何为内部 div 元素设置固定宽度

html - 当一个div在另一个div前面时如何屏蔽它

javascript - 如何让键盘+屏幕阅读器访问我的 Accordion ?

javascript - 我可以使用这段代码来设置 jQuery 中两个元素的高度吗?

javascript - 在 JQuery Step 中禁用左右键

html - 表项的内容选项卡

javascript - 单击链接时显示 jQuery Accordion?

javascript - 使用 Splunk 获取 CORS 错误

jquery - CSS + JQuery 页面淡出/淡入 - Safari 问题