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
Two CSS Files Defining Same Class
Are There Any Cons to Using Color Names in Place of Color Codes in CSS
Firefox @Font-Face with Local File - Downloadable Font: Download Failed
Flexbox VS Tables, Why Do We Need Flexbox
Change Text Color to White on Any Non-White Background
Does :Not() Negation Accept Descendant Selectors
How to Make a CSS Grid with Dynamic Number of Rows or Columns
Is There a CSS Way to Add an Arrow If a Ul Has a Ul Child
Webkit Animation Is Leaving Junk Pixels Behind on the Screen
Amp: How to Toggle a CSS Class
Horizontal Masonry Layout with Flexbox CSS Only
CSS Width 100% or Max-Width in Pixels
How to Use CSS Position Sticky to Keep a Sidebar Visible with Bootstrap 4
Change Parent Div on Input[Type=Checkbox]:Checked with CSS
Revert a Filter Invert() CSS Rule
Why Does This Calc() Function Not Work in Transform Scale