css - 使用 thymeleaf 设置 CSS 样式属性

标签 css thymeleaf

如何使用 thymeleaf 解析的 url 设置样式标签的背景属性。

我有

<div style="background:url('<url-to-image>')"></div>

有没有<img th:src="${@/<path-to-image>}">相当于在 thymeleaf 中设置样式属性。

最佳答案

如果您使用 th:style 设置您的样式属性,您可以实现这一点:

<div th:style="'background:url(' + @{/<path-to-image>} + ');'"></div>

检查 this thymeleaf 论坛上的帖子。

关于css - 使用 thymeleaf 设置 CSS 样式属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29140647/

相关文章:

html - CSS:响应式,背景图片问题

html - 使用 "if"条件的 thymeleaf 的 Spring 安全性

html - 如何为新的 Ionic "tabs"应用程序添加非选项卡式登录页面?

java - 单击提交后如何用数据填充两个实体

java.lang.IllegalArgumentException : Iteration variable cannot be null

spring - 属性 th :each is not allowed here(Error in Thymeleaf template)

java - Thymeleaf 找不到索引模板

jquery - 自定义从 map 制作者嵌入的谷歌地图

html - 相对于 parent 的最大高度不起作用

html - 中心动态宽度元素