简体   繁体   中英

Problem with css in Spring application Thymeleaf

I am currently trying to make a webpage but I can't tell why my html can't see the css file provided. I have an application in SpringBoot. I have the following files: index.html

<!DOCTYPE html>
<html lang="en">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>Menu</title>
    <link href="../static/style.css" th:href="@{/style.css}" rel="stylesheet" />
</head>
<body>
<nav>
    <ul>
        <li><a href="#"> View</a></li>
        <li><a href="#"> Notify </a></li>
        <li><a href="#"> A</a></li>
        <li><a href="#"> B</a></li>
    </ul>

</nav>

</body>
</html>

style.css

* {
    margin: 0;
    padding: 0;

}


ul  {



}


ul  li {

list-style: none;
display: inline-block;
float: left;
}

ul  li  a {

text-decoration: none;
font-size:14px;
font-family: arial;
color: #1e1e1e;
}

Structure of project: 在此处输入图像描述 Tried changing the root to the css file multiple times and tried even without thymeleaf however it doesn't work. Any help would be great. The html file works however the css file is not applied to it.

There are multiple ways to troubleshoot this issue.

  1. Try specifying type to link tag like below.

    type="text/css"

  2. Inspect elements in browser developer tool and check for what URL it is trying to load currently. From this you will get idea so that you can modify the css href path.

  3. Ensure that you have configured Resource handlers so that spring boot knows where to search for static resources exactly.

Refer: SpringBoot with Thymeleaf - css not found

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM