[英]How to change background color html attribute using thymelaf?
我正在嘗試在 web 應用程序中使用 model 中的特定值更改背景顏色。
<div class="card" style="width: 18rem; background: [[${task.color}]]" >
</div>
其中 task.color 是從 model 中選擇的默認 html 顏色的字符串值,但這種方式不起作用。
如何使用給定 DIV 上 model 的顏色集更改背景顏色?
謝謝
如果要 Thymeleaf 處理屬性,則必須在它們前面加上th:
。
<div class="card" th:style="|width: 18rem; background: ${task.color}|">
</div>
或者
<div class="card" style="width: 18rem;" th:styleAppend="|background: ${task.color}|">
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.