简体   繁体   English

无法在百里香中添加css文件

[英]Not able to add css file in thymeleaf

I am new in thymeleaf and trying to add .css file in thymeleaf but not able to load the css file. 我是thymeleaf的新手,试图在thymeleaf中添加.css文件,但无法加载css文件。 My css file is in src/main/resources/templates/style.css 我的css文件在src / main / resources / templates / style.css中

 <!DOCTYPE html>
 <html xmlns:th="http://www.thymeleaf.org">

 <head>
 <title>State 1 for Document</title>
 </head>

 <div th:if="${InstaPanState==1 and InstaPanStateStatus==0}">
 <head lang="en">
    <title>Instaveritas PAN Verification</title>
    <link rel='stylesheet prefetch' 
   href='https://fonts.googleapis.com/css?family=Open+Sans:400,300' 
    th:href="@{https://fonts.googleapis.com/css?
    family=Open+Sans:400,300}"/>
    <link rel='stylesheet prefetch' 
     href='https://fonts.googleapis.com/css?family=Open+Sans:400,300' 
     th:href="@{https://fonts.googleapis.com/css?
     family=Open+Sans:400,300}" />
    <link type="text/css" rel="stylesheet" href="style.css"  
    th:href="@{/style.css}" media="all"/>
</head>

您需要添加资源映射,请参见http://www.baeldung.com/spring-mvc-static-resources

You can create a folder under resources called static and a subfolder called css and move your css files there, something like: resources/static/css/style.css 您可以在名为static的资源下创建一个文件夹,并在名为css的子文件夹下创建一个css文件,然后将其移动到此处,例如: resources/static/css/style.css

Then call it like: 然后像这样调用它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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