下面是提供的代码。目前,由于 span 标签,它正在突出显示文本。但我希望它更改该表值的背景颜色而不是突出显示文本。我该怎么做?
<c:choose>
<c:when test="${manifest.manifestRtnedDate == null}">
<td class="backgroundHighLight">
<c:if test="${manifest.daysOpened >35 && manifest.daysOpened < 45 }">
<span style="background-color: #FFFF00"><c:out value="${manifest.daysOpened }"/></span>
</c:if>
<c:if test="${manifest.daysOpened > 45 }">
<span style="background-color: #FF4747"><c:out value="${manifest.daysOpened }"/></span>
</c:if>
</td>
</c:when>
<c:otherwise>
<td>
<c:out value="${ manifest.manifestRtnedDate}" />
</td>
</c:otherwise>
</c:choose>
最佳答案
您走在正确的轨道上,这里有两个选项。您可以:
保持逻辑不变,并尝试添加
display: block;
到你的 span 元素的样式。这应该让他们填写<td>
元素。或者……移动
td
元素本身进入c:if
block 并设置其背景样式而不是跨度(参见下面的示例)。
<c:choose>
<c:when test="${manifest.manifestRtnedDate == null}">
<c:if test="${manifest.daysOpened >35 && manifest.daysOpened < 45 }">
<td class="backgroundHighLight" style="background-color: #FFFF00">
<span><c:out value="${manifest.daysOpened }"/></span>
</td>
</c:if>
<c:if test="${manifest.daysOpened > 45 }">
<td class="backgroundHighLight" style="background-color: #FF4747">
<span><c:out value="${manifest.daysOpened }"/></span>
</td>
</c:if>
</c:when>
<c:otherwise>
<td>
<c:out value="${ manifest.manifestRtnedDate}" />
</td>
</c:otherwise>
</c:choose>
关于css - 更改表格背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45723094/