css - Thymeleaf - 解析外部 CSS 文件?表达式、变量等

标签 css spring thymeleaf

虽然我更倾向于说这是不可能的,但我似乎没有找到任何具体的答案。

但是,是否可以在外部 CSS 文件中使用 Thmymeleaf 表达式?例如,如果我有 ma​​in.css 并且它包含:

body {
    font-size: [[${fooBean.isLarge ? '22px;' : '16px;' }]];
}

.header {
    margin-top:
    background: url{[[${fooBean.isMain ? '/img/blue.jpg' : '/img/red.jpg' }]]}
                    no-repeat center center fixed;
}

这完全有可能使用 Thymeleaf 吗?

最佳答案

Thymeleaf 3 introduced new template modes .其中之一是 CSS,you can see an example of one here .您必须设置所有 spring 的东西/ Controller ,但您应该能够像平常一样使用它们(将您的 fooBean 添加到模型中)。

关于css - Thymeleaf - 解析外部 CSS 文件?表达式、变量等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43082116/

相关文章:

css - 如何从另一个 css 文件覆盖 css 样式?

javascript - 如何将网页快照及其所有元素(css、js、图像等)保存到一个文件中

java - ManyToOne 多个连接列,一个是默认值

java - 如何创建分组 Swagger 注释 - 此位置不允许使用注释

java - RestTemplate在java中处理[image/jpg]响应内容类型

java - 在 thymeleaf 中使用 db 列作为 img src

javascript - Thymeleaf:将文字与变量结合起来

javascript - 如何在多行文本的文本区域中添加换行符

html - CSS:在此示例中,设置右边距如何使元素的父元素变得可见?

java - Spring thymeleaf 实现