css - 更改交替行字体颜色

标签 css jsp jstl

我试过 tr:nth 元素......不工作

下面是我的jsp和css jsp 从 java 类中获取 2 个列表 如果列表为空则包括验证然后显示值 数据网格是表类

<table class="data-grid" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th colspan="6">Excesses to be actioned</th>
                </tr>
            </thead>
            <tr class="header">
                <th>Excess ID</th>
                <th>Date</th>
                <th>Client</th>
                <th>Product</th>
                <th>Amount</th>
                <th>DA</th>
            </tr>
            <tbody id="tbNa">
                <c:choose>
                    <c:when
                        test="${empty actionBean.excessList.newActiveCustomerExcessUIList}">
                        <tr>
                            <td colspan="6" align="center"><font color="red">No
                                    data available for Active Excess List</font></td>
                        </tr>
                    </c:when>
                    <c:otherwise>
                        <c:forEach
                            items="${actionBean.excessList.newActiveCustomerExcessUIList}"
                            var="customerExcess" varStatus="loop">
                            <c:set var="clientName" value="${customerExcess.clientName}"
                                scope="page"></c:set>
                            <c:set var="ultimateParent"
                                value="${customerExcess.ultimateParent}" scope="page"></c:set>
                            <c:set var="cif" value="${customerExcess.cif}" scope="page"></c:set>
                            <c:forEach items="${customerExcess.excessList}" var="excess">
                                <tr>
                                    <td><c:out value="${excess.excessId }"></c:out></td>
                                    <td><c:out value="${excess.openDate }"></c:out></td>
                                    <td><a href="#" onclick="openClientExcessPage('${cif}');"><c:out
                                                value="${clientName}"></c:out></a></td>
                                    <td><c:out value="${ultimateParent}"></c:out></td>
                                    <td><c:out value="${excess.excessAmount }"></c:out></td>
                                    <td><c:out value="${excess.excessDa}"></c:out></td>
                                </tr>
                            </c:forEach>
                        </c:forEach>
                    </c:otherwise>
                </c:choose>
                <c:choose>
                    <c:when
                        test="${empty actionBean.excessList.approvedCustomerExcessUIList}">
                        <tr>
                            <td colspan="6" align="center"><font color="red">No
                                    data available for Approved Excess List</font></td>
                        </tr>
                    </c:when>
                    <c:otherwise>
                        <c:forEach
                            items="${actionBean.excessList.approvedCustomerExcessUIList}"
                            var="customerExcess">
                            <c:set var="clientName" value="${customerExcess.clientName}"
                                scope="page"></c:set>
                            <c:set var="ultimateParent"
                                value="${customerExcess.ultimateParent}" scope="page"></c:set>
                            <c:forEach items="${customerExcess.excessList}" var="excess">
                                <tr>
                                    <td><c:out value="${excess.excessId }"></c:out></td>
                                    <td><c:out value="${excess.openDate }"></c:out></td>
                                    <td><a href="#" onclick="openClientExcessPage('${cif}');"><c:out
                                                value="${clientName}"></c:out></a></td>
                                    <td><c:out value="${ultimateParent}"></c:out></td>
                                    <td><c:out value="${excess.excessAmount }"></c:out></td>
                                    <td><c:out value="${excess.excessDa }"></c:out></td>
                                </tr>
                            </c:forEach>
                        </c:forEach>
                    </c:otherwise>
                </c:choose>
            </tbody>
        </table>

Data-grid 是表类...下面是为表写的css 我不想更改行颜色..我需要更改偶数行中数据的字体颜色

.data-grid {
    margin: 0px;
    padding: 0px;
    width : 60%;
    height : 40%;
    padding-top: 10%;   
    padding-left: 15%;
    white-space: nowrap;    
}

.data-grid select {
    padding: 3px 0px;
    border: 1px solid #DCDCDC;
}

.data-grid td {
    font-size: 11px;
    color: #000000;
    background-color: white;
    border: 0px;
    border-left: 1px;
    border-bottom: 1px;
    border-style: solid;
    border-color: #DBE5F1;
    padding: 5px;
}


.data-grid thead {
    color: #004080;
    font-size: 12px;
    font-weight: normal;
    border-color: #FFF;
    vertical-align: text-top;
    background-color: #C3C3C3;
    height: 20px;
    padding: 2px 5px;
}

.data-grid .header th {
    color: #002577;
    font-size: 11px;
    font-weight: bold;
    border-color: #FFF;
    text-align: center;
    vertical-align: text-top;
    background-color: #D5E0E6;
}

最佳答案

 .data-grid  tr:nth-child(even) {color: #CCC}
 .data-grid  tr:nth-child(odd) {color: #FFF} 

关于css - 更改交替行字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16536827/

相关文章:

java - <s :if> test expression evaluation for boolean value doesn't work as expected

java - 运行时出现空指针异常。

jsf - 使用 <c :if> with composite component 时出现重复 ID 异常

css - 闪烁在 Chrome 中不起作用

javascript - 如何使用 CSS 或 JS 使已访问的链接在悬停时更改颜色

javascript - HTML Div 将文本移动到下一行

java - 有没有办法重用<c :url> logic inside my custom JSP tag?

jsp - JSTL 或 JSP 中的 lastIndexOf

css - 如何从 Drupal 7 中的 H 标签中删除换行符?

javascript - Jquery Mobile - 关闭对话框后跳转固定标题(firefox)