【问题标题】:Insert css in thymeleaf template在百里香模板中插入css
【发布时间】:2019-12-19 20:20:47
【问题描述】:

我需要在电子邮件模板 (thymeleaf) 中插入样式。我需要为几个模板制作一个通用的 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样式。我也没有看到任何错误消息。

你能帮帮我吗?

谢谢,

曼努埃拉

【问题讨论】:

    标签: css thymeleaf


    【解决方案1】:

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

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

    在我复制它的项目中,我将片段用于整个标题。我不明白为什么它不适用于标题的“片段”。

    【讨论】:

      猜你喜欢
      • 2015-11-29
      • 2015-06-01
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多