html - Thymeleaf HTML if else 在同一行

标签 html css thymeleaf

我的 Thymeleaf HTML 页面中有这段代码,我想知道是否可以将 if else 放在同一语句中

<div th:if="${book.htmlIconColor != null}" >
<i class="fa fa-exchange fa-2x" th:style="${'color:' + book.htmlIconColor + '; text-align: center;'}" aria-hidden="true"></i>                     
</div>
<div th:if="${book.htmlIconColor == null}" >
<i class="fa fa-exchange fa-2x"  aria-hidden="true"></i>                     
</div>

最佳答案

尝试这样的事情:

condition ? first_expression : second_expression;

例如

<i class="fa fa-exchange fa-2x" aria-hidden="true" th:style="${book.htmlIconColor} ? 'color:' + ${book.htmlIconColor} + '; text-align: center;' : 'text-align: center;'"></i>

关于html - Thymeleaf HTML if else 在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44819904/

相关文章:

html - CSS 收缩元素不会导致跳转到下一行

html - CSS 目标特定类

java - Thymeleaf 选择选项重置为默认值

java - FontAwesome 没有显示在 Thymeleaf 中?

Thymeleaf 嵌套列表/ArrayList - 获取所有元素的总大小

html - 如何将 CSS 文件链接到我在 Rails 中的 View ?

html - CSS 文本悬停和过渡效果

html - 二、固定立柱工作台

javascript - 使用选项中的按钮创建选择输入

css - 用滚动条打印 md-dialog 内容