You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetSuite Advanced PDF 商品列表行交替背景色设置咨询

商品行交替背景色实现方案

实现思路

通过CSS的:nth-child()选择器实现商品行的交替背景色,同时用:not(:last-child)排除最后一行的配送行,确保它不参与交替规则。

代码示例

场景1:商品行与配送行有独立类名

假设你的HTML结构如下:

<table class="order-table">
  <tr class="product-row">商品行1</tr>
  <tr class="product-row">商品行2</tr>
  <tr class="product-row">商品行3</tr>
  <tr class="shipping-row">配送行</tr>
</table>

对应的CSS:

/* 奇数商品行背景白色 */
.order-table .product-row:nth-child(odd) {
  background-color: #ffffff;
}

/* 偶数商品行背景浅灰色 */
.order-table .product-row:nth-child(even) {
  background-color: #f0f0f0;
}

/* 配送行单独设置样式,不参与交替 */
.order-table .shipping-row {
  background-color: #e8e8e8; /* 可自定义颜色 */
}

场景2:商品行与配送行共用类名

如果所有行都使用同一个类名,仅最后一行是配送行:

<div class="order-container">
  <div class="row">商品行1</div>
  <div class="row">商品行2</div>
  <div class="row">商品行3</div>
  <div class="row">配送行</div>
</div>

对应的CSS:

/* 排除最后一行的商品行,设置交替背景 */
.order-container .row:not(:last-child):nth-child(odd) {
  background-color: #ffffff;
}

.order-container .row:not(:last-child):nth-child(even) {
  background-color: #f0f0f0;
}

/* 配送行样式 */
.order-container .row:last-child {
  background-color: #e8e8e8;
}

注意事项

  • 可以根据需求替换背景色的十六进制值,适配你的页面风格
  • 如果使用表格结构,确保<tr>元素的父容器是<tbody>或<table>,避免选择器失效

内容的提问来源于stack exchange,提问作者Daniel Shand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 09:57:44