使用thymeleaf设置CSS样式属性 [英] Setting CSS style attributes with thymeleaf

查看:3479
本文介绍了使用thymeleaf设置CSS样式属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用百里香解析的URL设置样式标签的background属性.

How to set the background property of a style tag with a thymeleaf resolved url.

我有

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

在百里香中是否有<img th:src="${@/<path-to-image>}">等价物用于设置样式属性.

Is there a <img th:src="${@/<path-to-image>}"> equivalent for setting style attributes in thymeleaf.

推荐答案

如果使用th:style设置样式属性,则可以实现:

You could achieve that if you use th:style to set your style attribute:

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

在百里香论坛上检查主题.

Check this thread on thymeleaf forum.

这篇关于使用thymeleaf设置CSS样式属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆