gpt4 book ai didi

html - Thymeleaf - 如何根据互斥条件应用两种(或更多)样式

转载 作者:太空宇宙 更新时间:2023-11-03 19:44:20 25 4
gpt4 key购买 nike

我需要让表格中的行具有备用背景色。我还需要让行中的文本颜色取决于一个值。我如何使用 Thymeleaf 做到这一点?这是我的代码:

<tr th:each="item, rowStat : ${items}" 
th:style="${rowStat.odd} ? 'background: #f0f0f2;' : 'background: #ffffff;'"
th:style="${item.getValue()} > 5 ? 'color: red;' : 'color: black;'">

<td.... <!-- cols>

</tr>

虽然这不起作用。 Thymeleaf 给出一个解析错误:Attribute "th:style"was already specified for element "tr".

更新

需要注意的是,这是一封 HTML 电子邮件,所以我需要使用内联样式。

最佳答案

Thymeleaf 有一个 th:styleappend 属性,允许应用多种样式:

<tr th:each="item, rowStat : ${items}" 
th:style="${rowStat.odd} ? 'background: #f0f0f2;' : 'background: #ffffff;'"
th:styleappend="${item.getValue()} > 5 ? 'color: red;' : 'color: black;'">

<td.... <!-- cols>

</tr>

关于html - Thymeleaf - 如何根据互斥条件应用两种(或更多)样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45044821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com