解决css中背景图片路径contextPath问题
一、场景
css:
background: url(https://blog.csdn.net/images/top.png) no-repeat center #000;
放到tomcat中启动,出现404,少了项目名称 myblog
404: http://localhost:8080/images/top.png
应该是:http://localhost:8080/myblog/images/top.png
二、解决方案
使用 @{/} 获取 myblog
<a class="top"
th:styleappend="'background:url(https://blog.csdn.net/'+@{/}+'images/top.png)
no-repeat center #000;'"></a>
本文详细阐述了在使用CSS时遇到的背景图片路径错误问题,特别是在Tomcat环境下,图片路径缺少项目名称导致的404错误。文章提供了一种解决方案,通过使用@{/}
904

被折叠的 条评论
为什么被折叠?



