Thymeleaf-如何根据互斥条件应用两种(或更多)样式 [英] Thymeleaf - How to apply two (or more) styles based on mutually exclusive conditions
本文介绍了Thymeleaf-如何根据互斥条件应用两种(或更多)样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要让表格中的行具有备用背景色.我还需要使行中的文本颜色取决于值.如何使用Thymeleaf做到这一点?这是我的代码:
I need to have rows in a table alternate background color. I also need to have the text color in the rows be dependent on a value. How can I do this using Thymeleaf? Here's the code that I have:
<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给出了一个解析错误:已经为元素"tr"指定了属性"th:style".
This doesn't work though. Thymeleaf give a parsing error : Attribute "th:style" was already specified for element "tr".
更新
请注意,这是一封HTML电子邮件,因此我需要使用内联样式.
Meant to note that this an HTML email so I need to use inline styles.
推荐答案
Thymeleaf具有th:styleappend属性,该属性允许应用多种样式:
Thymeleaf has a th:styleappend attribute that allows for multiple styles to be applied:
<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>
这篇关于Thymeleaf-如何根据互斥条件应用两种(或更多)样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文