---
title: "Card 组件 — zenit Zig UI"
description: "把标题、正文和可交互表面组织成一个视觉单元。default / outlined / elevated、selected、hoverable、interactive 与 pa…"
url: https://zenit.z.express/zh/components/card
language: zh-CN
alternate_en: https://zenit.z.express/components/card.md
alternate_es: https://zenit.z.express/es/components/card.md
alternate_ja: https://zenit.z.express/ja/components/card.md
alternate_ko: https://zenit.z.express/ko/components/card.md
alternate_fr: https://zenit.z.express/fr/components/card.md
alternate_de: https://zenit.z.express/de/components/card.md
project: zenit v0.1.0-alpha (Zig 0.15.2, macOS)
source: https://github.com/version-next/zenit
---

# Card

`ui.widgets.Card`

把标题、正文和可交互表面组织成一个视觉单元。

[Video](https://zenit.z.express/media/stories/card.mp4?v=772c2b7e2b)

**BEHAVIOR CONTRACT**

default / outlined / elevated、selected、hoverable、interactive 与 padding 策略显式区分。

**RECORDED INTERACTION**

录像展示 variants 和各类交互状态。

`examples/storybook/stories.zig:497`

```zig
// ── Card ──
pub fn buildCard(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 12);

    // ── 变体 ──
    try c.appendChild(a, try label(cx, "Variants (default / outlined / elevated)"));
    try c.appendChild(a, try W.Card(.{ .title = "Default", .subtitle = "with subtitle", .variant = .default, .width = 320 }).mount(scope, cx));
    try c.appendChild(a, try W.Card(.{ .title = "Outlined", .variant = .outlined, .width = 320 }).mount(scope, cx));
    try c.appendChild(a, try W.Card(.{ .title = "Elevated", .variant = .elevated, .width = 320 }).mount(scope, cx));

    // ── body ──
    try c.appendChild(a, try label(cx, "With body"));
    const res = try W.Card(.{ .title = "Card with body", .width = 320 }).mountBody(scope, cx);
    try res.body.appendChild(a, try ui.text(cx, "Body content goes here.", .{ .font_size = 13, .color = light.color.fg_secondary }));
    try c.appendChild(a, res.card);

    // ── 交互态 ──
    try c.appendChild(a, try label(cx, "States (selected / hoverable / interactive / no-pad)"));
    try c.appendChild(a, try W.Card(.{ .title = "Selected", .selected = true, .width = 320 }).mount(scope, cx));
    try c.appendChild(a, try W.Card(.{ .title = "Hoverable", .hoverable = true, .width = 320 }).mount(scope, cx));
    try c.appendChild(a, try W.Card(.{ .title = "Interactive", .interactive = true, .width = 320 }).mount(scope, cx));
    try c.appendChild(a, try W.Card(.{ .title = "No padding", .padded = false, .width = 320 }).mount(scope, cx));
    return c;
}
```

[在 GitHub 查看源码examples/storybook/stories.zig:497](https://github.com/version-next/zenit/blob/HEAD/examples/storybook/stories.zig#L497)

这是 Storybook 中该 story 的原样代码（zenit 5f9add5+wip 2026-09-30）。其中 `W` 即 `ui.widgets`，`col` / `row` / `label` 是 Storybook 内的布局小工具。

### CardProps

`ui.widgets.Card`

[src/ui/components/card/mod.zig:37](https://github.com/version-next/zenit/blob/HEAD/src/ui/components/card/mod.zig#L37)

```zig
fn Card(props: CardProps) CardBuilder
```

| 字段 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `title` | `?[]const u8` | `null` | 标题 |
| `subtitle` | `?[]const u8` | `null` | 副标题 |
| `variant` | `CardVariant` `.default` `.outlined` `.elevated` | `.default` | 变体 |
| `interactive` | `bool` | `false` | 可交互 |
| `hoverable` | `bool` | `false` | 可悬停 |
| `selected` | `bool` | `false` | 选中状态 |
| `padded` | `bool` | `true` | 内边距 |
| `width` | `?f32` | `null` | 宽度 |
| `height` | `?f32` | `null` | 高度 |
| `on_click` | `?core.HandlerRef` | `null` | 点击回调 |

### \*Node

`ui.widgets.Card`

mount 直接返回 `*Node`，把它 append 到父节点即可。
