Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 511
Maciaz Avatar asked Dec 05 '25 13:12

Maciaz


1 Answers

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}"/>
like image 86
juanlumn Avatar answered Dec 08 '25 02:12

juanlumn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!