【发布时间】:2016-06-17 19:16:30
【问题描述】:
我有一个 thymeleaf 模板,我没有导入 CSS 文件,并希望使用带有相对图像 URL 的 background-image: url{/image.jpg} 属性为 body 元素声明样式属性。我想在不包含应用程序上下文名称(/myapp/)的情况下加载 URL。它类似于here 的问题,只是它对我不起作用。
CSS:
<style>
body {
background: url(../img/Background.jpg)
no-repeat center center fixed;
background-size: cover;
}
</style>
但上面的 CSS 不起作用,它在
处访问了图像http://localhost/img/Background.jpg.
所以,我必须将值设为 url(/myapp/img/Background.jpg) 才能正确加载图像。
我在spring-context.xml 中正确设置了mvc:resources 配置,以便/img/ 请求正确加载,并且它可以在其他地方工作。
spring-context.xml
<mvc:resources mapping="img/**" location="/WEB-INF/img/" />
那么如何使用thymeleaf的相对url动态加载背景url图片css值呢?
【问题讨论】:
标签: css background-image thymeleaf relative-path