[英]Insert css in thymeleaf template
我需要在電子郵件模板(百里香)中插入樣式。 我需要為幾個模板制作一個通用的CSS文件。
使用Spring Boot 1.3.3
我嘗試遵循以下帖子中的內容: Thymeleaf + CSS + SpringBoot
電子郵件文件:資源>郵件>“ email.html” css文件:資源>靜態> css>“ styles.css”
我對郵件使用WebContext(我曾經使用Context,但是Context不接受相對路徑,因此需要WebContext)。
在我的CSS中:
h1 {
color: #78ab46;
}
在我的模板中:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title > Hello </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="all"
href="../static/css/styles.css" th:href="@{/css/styles.css}" />
</head>
<body>
<h1> Hello </h1>
</body>
結果是發送了郵件,但沒有考慮css樣式。 我也沒有看到任何錯誤消息。
請問你能幫幫我嗎?
謝謝,
Manuela
過去,我使用片段來處理此類事情。
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<div th:replace="fragments/email-header :: head"></div>
<title > Hello </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1> Hello </h1>
</body>
然后在fragments文件夾中,我有一個文件email-header.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<style>
h1 {
color: #78ab46;
}
</style>
</html>
在我將其復制出來的項目中,我將該片段用於整個標題。 我不明白為什么它對於標題的“片段”不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.