Thymeleaf: how to use conditionals to dynamically add/remove a CSS class

后端 未结 10 1080
無奈伤痛
無奈伤痛 2020-12-12 15:04

By using Thymeleaf as template engine, is it possible to add/remove dynamically a CSS class to/from a simple div with the th:if clause?

Nor

10条回答
  •  攒了一身酷
    2020-12-12 15:05

    Yet another usage of th:class, same as @NewbLeech and @Charles have posted, but simplified to maximum if there is no "else" case:

    
    

    Does not include class attribute if #fields.hasErrors('password') is false.

提交回复
热议问题