0

I m trying to create a sidebar where I have a style.css for customize it. When I inspect my page, it seems it never loads and get 404 not found.

<head>
<h1>sidebar</h1>
<title>Responsive Sidebar Menu</title>
<link rel="stylesheet" type="text/css" href="style.css"></head>

My project is structured like in the following picture:

enter image description here

I can't figure out how to write the path so it can load properly.

Reporter
  • 3,897
  • 5
  • 33
  • 47
elskersan
  • 1
  • 3

1 Answers1

0

Move your template folder right under resources:

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" />
Zaur
  • 206
  • 2
  • 4
  • i tried just now since my front is built with thymeleaf, but it doenst work...i dont get, if i press ctrl+click it goes to the style file, but when i reload the server and access localhost:8080/testpage, it doenst show the style, and on inspect i can see that the request is 404 on style.css – elskersan May 20 '21 at 11:05
  • any reason it s happening? – elskersan May 20 '21 at 11:05
  • Please read this answer https://stackoverflow.com/questions/41506091/css-and-java-script-not-rendering-404-error-spring-boot – Zaur May 20 '21 at 11:10
  • this is how looks my include command – elskersan May 20 '21 at 11:38
  • it is in static already , but when i reload the server, it never show on the page – elskersan May 20 '21 at 11:39
  • Zaur thanks, it worked indeed, but i dont get why wouldn t it take the right path...but anyway, it works now – elskersan May 20 '21 at 11:46
  • Please my answer check correct Everybody see that the problem is right – Zaur May 20 '21 at 11:48