Maciaz
Maciaz

Reputation: 1234

Custom .css file doesn't work with Thymeleaf & Spring MVC

So, I've spent like last hour trying to solve it, but I just can't get custom .css file to get linked with html files in Spring 5. I'm using Thymeleaf, Bootstrap & jQuery for frontend works. I'm using Intellij Community Edition.

My files hierarchy looks like this:

java
    project_files
resources
    static
        css
          main.css
    templates
        main.html

I have a line in main.html:

<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" href="../../css/main.css"/>

that should link my styles with the .html file. What can be wrong?

Upvotes: 3

Views: 4806

Answers (1)

juanlumn
juanlumn

Reputation: 7135

Try changing a little bit your folder structure, create a folder under resources called static, and a folder called css under static and place the css files there, something like:

🗁 resources
└─── 🗁 static
    └─── 🗁 css
        └─── main.css

Then you should be able to access it by using:

 <link rel="stylesheet" type="text/css" th:href="@{/css/main.css}"/>

Upvotes: 6

Related Questions