java - 如何编写路径以便 style.css 可以在我的 localhost 页面上重新加载?
问题描述
我正在尝试创建一个侧边栏,其中有一个 style.css 用于自定义它。当我检查我的页面时,它似乎永远不会加载并且找不到 404。
<head>
<h1>sidebar</h1>
<title>Responsive Sidebar Menu</title>
<link rel="stylesheet" type="text/css" href="style.css"></head>
我的项目结构如下图所示:
我不知道如何编写路径以便它可以正确加载。
解决方案
将您的模板文件夹移动到资源下:
src/main/resource/static/css (for CSS files);
src/main/resource/templates (for HTML templates).
Then correct the link tag as follows:
<link href="../static/css/style.css" th:href="@{/css/style.css}" rel="stylesheet" />
推荐阅读
- reactjs - 如何在我的 React 组件中使用 SCSS 变量
- microsoft-graph-api - 如何使用 Microsoft API 将文件上传到不同域共享的文件夹?
- javascript - 使用 JavaScript 在 IE11 中禁用 Alt+Home
- node.js - 使用 lambda nodejs 从 s3 缓冲一个 gz 文件
- swift - 从视图层次结构中查找和隐藏视图
- python - 将小数格式化为百分比并截断其余部分
- php - 如果某天为空,则创建最近 30 天的图表
- git - docker:git clone 结果不在本地卷中,args 没有扩展
- arrays - 在 Julia 中将数组导出到 CSV 文件
- java - Prometheus 错误:收集器已注册,提供名称:http_client_requests_count