【发布时间】:2017-02-27 13:35:14
【问题描述】:
我正在使用 Spring MVC 和 Thymeleaf 视图引擎。我有一个外部 style.css 文件,其中包含我页面的 CSS。在 CSS 文件中,我想引用相对图像 URL。
这是我的 style.css 文件:
.background {
width: 100%;
background-image: url('/path/to/image/bg.png');
}
上面尝试使用以下不存在的 URL 访问图像:
http://localhost/path/to/image/bg.png
我的真实形象在:
http://localhost/myapp/path/to/image/bg.png
这个 StackOverflow 问题回答了我的内联 CSS 问题:How to set background url for css files in thymeleaf?
但是如何为外部 .css 文件执行此操作?
【问题讨论】:
标签: css background-image thymeleaf relative-path