css - 在 thymeleaf 模板中插入 css

标签 css thymeleaf

我需要在电子邮件模板 (thymeleaf) 中插入样式。我需要为几个模板制作一个通用的 css 文件。

使用spring boot 1.3.3

我试着按照以下帖子中的内容进行操作: Thymeleaf + CSS+SpringBoot

电子邮件文件:资源 > 邮件 > "email.html" css 文件:resources > static > 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样式。我也没有看到任何错误消息。

你能帮帮我吗?

谢谢,

曼努埃拉

最佳答案

过去我使用片段来处理这种事情。

<!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>

然后在片段文件夹中我有一个文件 email-header.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
    <style>
        h1 {
            color: #78ab46;
        }
    </style>
</html>

在我复制它的元素中,我使用了整个标题的片段。我不明白为什么它不适用于 header 的“片段”。

关于css - 在 thymeleaf 模板中插入 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57474988/

相关文章:

javascript - thymeleaf - 脚本和 :block

java - 使用 Thymeleaf 在 EL 表达式中进行类型转换

javascript - TinyMCE 4 编辑器内容换行

jquery - 如何修复 jquery 数据表单元格宽度?

JQuery 对话框和 Datatable 一起工作

java - 在 Thymeleaf 中根据特定条件使图像可点击

java - Spring Boot 和 Thymeleaf : Object id field is null when sending back to controller

html - 在 Angular 中滚动浏览器页面时修复表格 thead

css - Wired.com超链接样式的纯CSS实现

html - BBC风格的菜单悬停效果