首页 > 解决方案 > 如何编写路径以便 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>

我的项目结构如下图所示:

在此处输入图像描述

我不知道如何编写路径以便它可以正确加载。

标签: javahtmlcssspring-bootfrontend

解决方案


将您的模板文件夹移动到资源下:

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" />

推荐阅读