如何使用百万美分解析的URL设置样式标记的背景属性.
我有
<div style="background:url('<url-to-image>')"></div>
Run Code Online (Sandbox Code Playgroud)
<img th:src="${@/<path-to-image>}">在thymeleaf中是否有相应的设置样式属性.
Lea*_*edo 38
如果您使用th:style设置样式属性,则可以实现此目的:
<div th:style="'background:url(' + @{/<path-to-image>} + ');'"></div>
Run Code Online (Sandbox Code Playgroud)
在thymeleaf论坛上查看此主题.
@Leandro Carracedo 建议的答案对我不起作用(但它在此过程中有所帮助),我不得不添加第二对括号和 '$' 以从变量中获取值
<td th:style="'font-size:'+@{${headerTemplateTextSize}}+'; -webkit-margin-before: 0.67em; -webkit-margin-after: 0.67em; -webkit-margin-start: 0px;-webkit-margin-end: 0px; font-weight: 300; max-width: 100px'">
<div>...</div>
</td>
Run Code Online (Sandbox Code Playgroud)
您还可以使用文字替换:
<div th:style="|background:url(@{/<path-to-image>});|"></div>
Run Code Online (Sandbox Code Playgroud)