如何使用2种单独的颜色替换表行,但我将标题行替换为另一种颜色.可能吗?我需要使用循环技术.哦,不,我不允许发布图片.但它看起来像一个有5行的表,标题行是蓝色,而其他4行是红色>白色>红色>白色
Bal*_*usC 11
使用<c:forEach>了varStatusCSS的一些线路.
<table>
<thead>
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
</tr>
</thead>
<tbody>
<c:forEach items="${bean.list}" var="item" varStatus="loop">
<tr class="${loop.index % 2 == 0 ? 'even' : 'odd'}">
<td>${item.property1}</td>
<td>${item.property2}</td>
<td>${item.property3}</td>
</tr>
</c:forEach>
<tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
用CSS
tr.even { background: red; }
tr.odd { background: white; }
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,标题刚刚与正文分开.当正文中的表行索引是2(偶数)的倍数时,则得到class="even",否则class="odd"(在浏览器中打开页面,右键单击它并查看源代码以自己查看).使用CSS,您可以控制各个元素的样式.要为标题行添加蓝色背景,只需添加即可
thead tr { background: blue; }
Run Code Online (Sandbox Code Playgroud)