Thymeleaf + CSS+Springboot

Thymeleaf + CSS+SpringBoot

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/Layout.css" th:href="@{/css/Layout.css}" rel="stylesheet" />

Spring Boot, Thymeleaf and CSS

Instead of

<link rel="stylesheet" href="css/main.css"/>

Use this :

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

and make sure this is your file placeholders

src/main/resource/static/css - for CSS files

src/main/resource/templates - for HTML templates files

How to add css files to Spring boot application (Thymeleaf) pagination

try to add additional / at start here before assets

<link href="/assets/css/font-awesome.min.css" rel="stylesheet">

Add css with thymeleaf

Since you use Spring-Boot, the path should be recognized automatically. The project structure should be alike:

  • resources/static/js
  • resources/static/css

In case there are no other overridden methods, remove the WebConfig class with the annotations. I recommend avoiding using the @EnableWebMvc with Spring-Boot since you take all the control (and responsibility) over the MVC configuration.

Access to a static resource with:

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

Spring Boot cant serve css file with Thymeleaf View

The issue was actually in my CSS file :) . Apparently i had selectors for classes that werent present in the html. After removing them the solution proposed in the comments worked fine!



Related Topics



Leave a reply



Submit