¥API Reference
此组件基于 span
元素并支持 常用边距属性。
¥This component is based on the span
element and supports common margin props.
¥Examples
¥As another element
使用 as
属性将文本渲染为 p
、label
、div
或 span
。此属性纯粹是语义性的,不会改变视觉外观。
¥Use the as
prop to render text as a p
, label
, div
or span
. This prop is purely semantic and does not alter visual appearance.
¥Size
使用 size
属性控制文本大小。此属性还提供正确的行高和校正的字母间距 - 随着文本大小的增加,相对行高和字母间距会减小。
¥Use the size
prop to control text size. This prop also provides correct line height and corrective letter spacing—as text size increases, the relative line height and letter spacing decrease.
2-4 号尺寸设计用于长篇内容。
¥Sizes 2–4 are designed to work well for long-form content.
1-3 号尺寸设计用于 UI 标签。
¥Sizes 1–3 are designed to work well for UI labels.
¥Weight
使用 weight
属性设置文本粗细。
¥Use the weight
prop to set the text weight.
¥Align
使用 align
属性设置文本对齐方式。
¥Use the align
prop to set text alignment.
¥Trim
使用 trim
属性修剪文本框开头、结尾或两侧的前导空格。
¥Use the trim
prop to trim the leading space at the start, end, or both sides of the text box.
该 prop 的工作原理与即将发布的 半行距控件 规范类似,但底层使用了通用的 负边距解决方法 以实现跨浏览器支持。
¥The prop works similarly to the upcoming half-leading control spec, but uses a common negative margin workaround under the hood for cross-browser support.
在卡片或其他“盒状”组件中调整垂直间距时,修剪行距非常有用。否则,顶部和底部的内边距看起来会比侧面的大。
¥Trimming the leading is useful when dialing in vertical spacing in cards or other “boxy” components. Otherwise, padding looks larger on top and bottom than on the sides.
默认的修剪值是根据 Radix Themes 使用的系统字体堆栈配置的。如果你使用自定义字体,可以使用相应的 CSS 变量对修剪值进行 adjust 处理。
¥The default trim values are configured for the system font stack that’s used by Radix Themes. If you are using custom fonts, you can adjust the trim values using the corresponding CSS variables.
¥Truncate
当文本溢出容器时,使用 truncate
属性用省略号截断文本。
¥Use the truncate
prop to truncate text with an ellipsis when it overflows its container.
使用 wrap
属性控制文本换行。
¥Use the wrap
prop to control text wrapping.
text-wrap: pretty
is an experimental value that is not yet supported in all browsers. However, it can be treated as a progressive enhancement for browsers that do support it.
¥Color
使用 color
属性指定特定的 color。文本颜色设计为与常见背景颜色至少达到 Lc 60 APCA 对比度。
¥Use the color
prop to assign a specific color. The text colors are designed to achieve at least Lc 60 APCA contrast over common background colors.
¥High-contrast
使用 highContrast
属性增加与背景的颜色对比度。
¥Use the highContrast
prop to increase color contrast with the background.
¥With formatting
使用格式化组件组合 Text
,以增强内容的强调和结构。
¥Compose Text
with formatting components to add emphasis and structure to content.
¥With form controls
将 Text
与表单控件(例如 Checkbox
、RadioGroup
或 Switch
)组合,即使文本是多行的,也会自动将控件与第一行文本居中。
¥Composing Text
with a form control like Checkbox
, RadioGroup
, or Switch
automatically centers the control with the first line of text, even when the text is multi-line.