本页为译文。技术支持和视频教程主要使用英语,内容以英文页面为准。 英文版
Card
Card 是带边框的容器:页眉包含标题、说明和右侧的操作,然后是内容,再是页脚。


如何制作带页眉操作和页脚的卡片:
<tb:Card
title="Plan"
description="Your plan renews on the first day of each month.">
<ui:Button text="Change" class="tb-card__action" />
<ui:Label text="Pro, 5 seats" />
<ui:Label text="12 GB of 50 GB used" />
<ui:Button text="Cancel the plan" class="tb-card__footer" />
<ui:Button text="Add seats" class="tb-card__footer" />
</tb:Card>
var card = new Card
{
Title = "Plan",
Description = "Your plan renews on the first day of each month."
};
card.Add(new Label("Pro, 5 seats"));
card.Action.Add(new Button(changePlan) { text = "Change" });
card.Footer.Add(new Button(addSeats) { text = "Add seats" });
标题是一个 AnimatedLabel,所以效果标签在其中有效。一个会闪光的金色渐变传奇标题:
quest.Title = "<gradient=#ff9f1c,#ffe066><shine>"
+ "The Hollow King</shine></gradient>";
这些颜色用于深色卡片,如默认的 toolbox 主题。在浅色卡片上请使用更深的颜色,使标题保持 4.5:1 的对比度。
| 成员 | 说明 |
|---|---|
Title (title) |
页眉的粗体行。空标题不显示这一行。<wave> 这样的效果标签在其中有效;没有标签的标题每帧不做任何工作。 |
Description (description) |
标题下方弱化的文本。富文本标签有效。空说明不显示这一行。 |
Icon (icon) |
标题栏左侧的图片,在标题和描述的列上居中。它使用 --tb-color-text-muted 着色。没有图片时不显示,也不占空间。 |
Action |
页眉右侧的位置。从代码中向其添加页眉按钮。 |
Footer |
内容下方的一行。从代码中向其添加页脚按钮。 |
- 卡片的子元素就是它的内容。
- 带有类
tb-card__action的子元素进入页眉,位于标题右侧。带有类tb-card__footer的子元素进入页脚。卡片在附加到面板时移动这些子元素。 - 只有当卡片有标题、说明或操作时才显示页眉。空的页脚不占空间。
- 过长的标题或说明会换行。
像设置页面一样的设置行:左侧图标、粗体标题、柔和的描述,右侧是分段选择器。选择器是放在操作插槽中的 ToggleButtonGroup:
<tb:Card
icon="project://database/Assets/Icons/density.png"
title="Density"
description="How much room the lists take.">
<ui:ToggleButtonGroup class="tb-card__action"
allow-empty-selection="false">
<ui:Button text="Comfortable" />
<ui:Button text="Compact" />
</ui:ToggleButtonGroup>
</tb:Card>
提示:
- 一张卡片用于一个主题:一个方案、一个用户、一个存档。对于同类行的列表,请使用
ListItem。 - 把卡片的主按钮放进页脚,把 "Edit" 这样的小按钮放进页眉。
- 对于只有页眉操作、且由代码稍后添加的卡片,也请设置标题。卡片会在附加时查找该操作。
- 在
GridPanel中放置卡片可得到仪表板。
在示例中

样式
| 类 | 元素 |
|---|---|
tb-card |
卡片:--tb-color-surface 背景、--tb-color-border 边框、--tb-radius-md 圆角和 --tb-spacing-md 内边距。 |
tb-card__header |
包含文本和操作的行。没有内容时隐藏。 |
tb-card__icon |
标题栏左侧的图片。大小为 --tb-size-button 的方块,颜色为 --tb-color-text-muted。没有图片时隐藏。 |
tb-card__headings |
包含标题和说明的列。 |
tb-card__title |
大字号的粗体标题,一个没有 tb-animated-label 类的 AnimatedLabel。 |
tb-card__description |
--tb-color-text-muted 的说明。 |
tb-card__action-slot |
页眉右侧的行。 |
tb-card__content |
内容子元素的父级。 |
tb-card__footer-slot |
内容下方的行。 |
tb-card__action |
放在子元素上,可将该子元素送入页眉。 |
tb-card__footer |
放在子元素上,可将该子元素送入页脚。 |
.tb-card {
padding: 16px;
background-color: var(--tb-color-surface-alt);
}
.tb-card__footer-slot { justify-content: flex-end; }
CardDemo 场景展示了:使用默认值的每日奖励、用代码制作的商店物品卡片、带印章和目标的任务,以及角色卡片。