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

后端 未结 10 1099
無奈伤痛
無奈伤痛 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:28

    What @Nilsi mentioned is perfectly correct. However, adminclass and user class need to be wrapped in single quotes as this might fail due to Thymeleaf looking for adminClass or userclass variables which should be strings. That said,

    it should be: -

      
     
    

    or just:

     
     
    

提交回复
热议问题