reference a .css file with thymeleaf in spring mvc

后端 未结 2 491
借酒劲吻你
借酒劲吻你 2021-02-08 09:52

I am doing a project with spring MVC and Thymeleaf. I have a question about how I should reference my CSS files if I have this folder structure:

src
  main
             


        
相关标签:
2条回答
  • 2021-02-08 10:16

    I have such problem!That steps helped me.

    1. I have the directory /resources/css/myCSS.css. So I had put css into root like /css/myCSS.css and removed directory /resources
    2. I link MyCSS like this:

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

    0 讨论(0)
  • 2021-02-08 10:28

    You will need to use th:href attribute for referring css files. Here is a sample from thymeleaf tutorial. If thymeleaf can not evaluate th:href value, it defaults to href value.

    <head>
        <title>Good Thymes Virtual Grocery</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" media="all"  
          href="../../css/gtvg.css" th:href="@{/css/gtvg.css}" />
     </head>
    
    0 讨论(0)
提交回复
热议问题