Thymeleaf - How to apply two (or more) styles based on mutually exclusive conditions

Viewed 8403

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>

This doesn't work though. Thymeleaf give a parsing error : Attribute "th:style" was already specified for element "tr".

Update

Meant to note that this an HTML email so I need to use inline styles.

1 Answers
Related