I have a spring boot application. Now I need to add css to it. I added a css file and the link to it in the html file. But for some reason it's not working.
This is how I've done it.
Added csstest.css file below to src/main/resources/static/css.
body { background-color: blue; } h1 { color: red; margin-left: 20px; }
Added the following code to test.html at src/main/resources/templates.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" type="text/css" href="css/csstest.css"/> </head> <body> <h1>This text should be styled, but it's not.</h1> </body> </html>
But when I open the html page the css is not being applied. Why?
I've seen a tutorial telling to add a configuration on dispatcher-servlet.xml. But my application is a spring boot app that doesn't have that file. The tutorial was not for a spring boot app (which is my case). The tutorials for spring boot don't tell to do that. So not sure what's the issue.
https://stackoverflow.com/questions/65534636/how-to-add-css-to-a-spring-boot-application January 02, 2021 at 07:27AM
没有评论:
发表评论