R

ReflexKR

Reflex 官方文档

组件工坊:Reflex 组件库 100 例

·

课程概览

布局

·

Box

·

Flex

·

Stack

·

Grid

·

Container

·

Section

·

Center

·

Spacer

·

Separator

·

Card

·

Inset

·

Aspect Ratio

·

Fragment

排版

·

Text

·

Heading

·

Link

·

Code

·

Markdown

·

Blockquote

·

Quote

·

Strong

·

Em

·

Kbd

表单

·

Button

·

Input

·

Text Area

·

Checkbox

·

Switch

·

Radio Group

·

Select

·

Slider

·

Form

·

Upload

数据展示

·

Badge

·

Avatar

·

Icon

·

Callout

·

List

·

Data List

·

Code Block

·

Progress

·

Spinner

·

Scroll Area

·

Moment

展开与切换

·

Tabs

·

Accordion

·

Segmented Control

浮层

·

Tooltip

·

Popover

·

Hover Card

·

Dialog

·

Alert Dialog

·

Drawer

·

Dropdown Menu

·

Context Menu

·

Toast

动态渲染

·

Cond

·

Match

·

Foreach

·

Auto Scroll

媒体

·

Image

·

Audio

·

Video

表格与数据网格

·

Table

·

Data Table

·

Data Editor

图表

·

Area Chart

·

Bar Chart

·

Line Chart

·

Composed Chart

·

Pie Chart

·

Radar Chart

·

Radial Bar Chart

·

Scatter Chart

·

Funnel Chart

·

Treemap

·

Sankey Chart

·

Error Bar

图表部件

·

Axis

·

Cartesian Grid

·

Chart Tooltip

·

Legend

·

Label

·

Reference

·

Brush

其他图表库

·

Plotly

·

Pyplot

HTML 元素

·

HTML

·

HTML Text

·

HTML Layout

·

HTML Forms

·

HTML Media

·

HTML Tables

·

SVG

其他工具

·

Theme

·

Skeleton

·

Clipboard

·

Html Embed

·

Script

·

Memo

组件工坊:Reflex 组件库 100 例
布局

Section

rx.section

官方文档

工坊订单

请把介绍页按“功能”“价格”这样分成几大块,每块上下留出充足的空白。

rx.section 表示页面内容中的一个区块。它渲染为 HTML <section> 元素,默认带有上下内边距。它首先是一个表达语义的组件,用来把彼此相关的内容(比如一个标题和它下面的正文)归成一块。

First

This is the first content section

Second

This is the second content section

rx.box(
    rx.section(
        rx.heading("First", as_="h2", size="4"),
        rx.text("This is the first content section"),
        padding_x="12px",
        background_color="var(--gray-2)",
    ),
    rx.section(
        rx.heading("Second", as_="h2", size="4"),
        rx.text("This is the second content section"),
        padding_x="12px",
        background_color="var(--gray-3)",
    ),
    width="100%",
)

试着改属性

Section 只有 size 一个属性,用来决定上下留白的大小。注意看虚线之间的空白如何变化。

试着改属性

Features

Vertical padding comes from the size prop.

size

rx.box(
    rx.section(
        rx.heading("Features", as_="h2", size="4"),
        rx.text("Vertical padding comes from the size prop."),
        size="2",
        padding_x="12px",
        background_color="var(--accent-2)",
        border_top="1px dashed var(--accent-8)",
        border_bottom="1px dashed var(--accent-8)",
    ),
    width="100%",
)
size 1 是 24px,2 是 40px,3 是 64px 的上下留白。左右没有留白,需要用 padding_x 另行设置。
属性取值默认值用途
size"1"(24px) "2"(40px) "3"(64px)"2"上下内边距
padding_x 等 CSSCSS 长度无左右默认没有留白

size 可以用 rx.breakpoints(...) 按屏幕宽度给出不同的值。Radix Themes 还有 size="4"(80px),但已安装的 0.10 的 rx.section 只接受 "1"~"3"。

三种尺寸

把只有尺寸不同的三个 Section 并排放置。文字相同,只有上下留白不同。

size 1

size 2

size 3

rx.flex(
    rx.section(rx.text("size 1"), size="1", padding_x="12px", background_color="var(--gray-3)"),
    rx.section(rx.text("size 2"), size="2", padding_x="12px", background_color="var(--gray-4)"),
    rx.section(rx.text("size 3"), size="3", padding_x="12px", background_color="var(--gray-5)"),
    spacing="3",
    align="start",
    width="100%",
)

按屏幕宽度改变留白

想在手机上减少留白、在宽屏上增加留白时,给 size 传入 rx.breakpoints。

Small padding on phones, more on wide screens

rx.section(
    rx.text("Small padding on phones, more on wide screens"),
    size=rx.breakpoints(initial="1", md="3"),
    padding_x="12px",
    background_color="var(--gray-3)",
    width="100%",
)

和 Box 有什么不同

rx.box 是没有语义的 <div>,而 rx.section 是带有“从这里开始是一个区块”含义的 <section>。屏幕阅读器和搜索引擎会把这种区分当作文档结构来读取。每个区块用 rx.heading 加上标题,结构会更清晰。常见的写法是用 rx.container 限定整页宽度,再在里面用 Section 分区。

完成订单

用 Container 限定正文宽度,把“功能”和“价格”各自分成一个 Section。中间的 rx.separator() 标出区块的分界。

Features

Pure Python, from the front end to the back end.

Pricing

Free to start. Pay when your app grows.

rx.container(
    rx.section(
        rx.heading("Features", as_="h2", size="5"),
        rx.text("Pure Python, from the front end to the back end."),
        size="2",
    ),
    rx.separator(),
    rx.section(
        rx.heading("Pricing", as_="h2", size="5"),
        rx.text("Free to start. Pay when your app grows."),
        size="2",
    ),
    size="2",
    width="100%",
)

工坊笔记

  • rx.section 是 <section> 元素,是把相关内容归为一个区块的语义组件。

  • size "1"~"3" 对应上下留白 24·40·64px。默认是 "2"。

  • 左右没有留白,需要用 padding_x 另行设置。

  • 每个区块用 rx.heading 加上标题。

  • 用 rx.container 限定宽度,在里面用 rx.section 分区。

← 上一课

布局 · Container

下一课 →

布局 · Center

订阅新课时和新课程通知

本课程新增课时或推出后续课程时,我们会发邮件通知你。

收集项目:电子邮箱 · 用途:本课程的新课时和上线通知 · 保存期限:直到你要求删除。不会用于其他用途,也不会提供给他人。回复任意通知邮件,我们会立即删除。

问答

关于本课有任何疑问都可以在这里留言。所有语言版本页面的提问会汇集在一起。

以纯文本显示,不支持链接和格式。

R

ReflexKR

动手学 Python 和 Reflex。所有示例均已在 Reflex 0.10.0 上实际运行验证。

ReflexKR 免费,没有横幅广告。如果对你有帮助,欢迎请我们喝杯咖啡。 ☕ 请我们喝杯咖啡

联盟链接与赞助说明
한국어English日本語简体中文EspañolDeutsch

© 2026 ReflexKR · Since 2026 · CC BY-NC 4.0

Built with Reflex