Styles
Native UI 只渲染白名单里的工具类。在任意 nx-* 组件上写这些类名,组件会使用白名单里的类。Angular 模板用 class,React 用 className。
使用
<nx-box class="flex p-3 bg-default rounded-medium">
<nx-text class="text-secondary fs-small">Styles</nx-text>
</nx-box><NxBox className="flex p-3 bg-default rounded-medium">
<NxText className="text-secondary fs-small">Styles</NxText>
</NxBox>布局
控制元素的显示方式、定位、浮动、溢出、可见性和层叠。
Display
| 类名 | 描述 |
|---|---|
inline | display: inline |
block | display: block |
inline-block | display: inline-block |
flex | display: flex |
inline-flex | display: inline-flex |
table | display: table |
table-row | display: table-row |
table-cell | display: table-cell |
hidden | display: none |
hidden 会从布局中拿掉元素。只想保留占位、不显示内容时用下面的 invisible。
定位
| 类名 | 描述 |
|---|---|
static | position: static |
relative | position: relative |
absolute | position: absolute |
fixed | position: fixed |
sticky | position: sticky |
溢出
auto、visible、hidden、scroll 可以作用在两个方向,或只作用在水平、垂直方向。
| 类名 | 描述 |
|---|---|
overflow-auto | overflow: auto |
overflow-visible | overflow: visible |
overflow-hidden | overflow: hidden |
overflow-scroll | overflow: scroll |
overflow-x-auto | overflow-x: auto |
overflow-x-visible | overflow-x: visible |
overflow-x-hidden | overflow-x: hidden |
overflow-x-scroll | overflow-x: scroll |
overflow-y-auto | overflow-y: auto |
overflow-y-visible | overflow-y: visible |
overflow-y-hidden | overflow-y: hidden |
overflow-y-scroll | overflow-y: scroll |
浮动
| 类名 | 描述 |
|---|---|
float-left | float: left |
float-right | float: right |
float-none | float: none |
clearfix | 清除子元素浮动 |
可见性
| 类名 | 描述 |
|---|---|
visible | visibility: visible |
invisible | visibility: hidden |
层叠
| 类名 | 描述 |
|---|---|
z-n1 | z-index: -1 |
z-0 | z-index: 0 |
z-1 | z-index: 1 |
z-2 | z-index: 2 |
z-3 | z-index: 3 |
弹性布局
这些类名作用在已经是 flex 容器或 flex 子项的元素上。容器本身用布局里的 flex 或 inline-flex。
方向与换行
| 类名 | 描述 |
|---|---|
flex-row | flex-direction: row |
flex-row-reverse | flex-direction: row-reverse |
flex-column | flex-direction: column |
flex-column-reverse | flex-direction: column-reverse |
flex-wrap | flex-wrap: wrap |
flex-nowrap | flex-wrap: nowrap |
flex-wrap-reverse | flex-wrap: wrap-reverse |
主轴对齐
| 类名 | 描述 |
|---|---|
justify-content-start | justify-content: flex-start |
justify-content-end | justify-content: flex-end |
justify-content-center | justify-content: center |
justify-content-between | justify-content: space-between |
justify-content-around | justify-content: space-around |
交叉轴对齐
| 类名 | 描述 |
|---|---|
align-items-start | align-items: flex-start |
align-items-end | align-items: flex-end |
align-items-center | align-items: center |
align-items-baseline | align-items: baseline |
align-items-stretch | align-items: stretch |
多行对齐
| 类名 | 描述 |
|---|---|
align-content-start | align-content: flex-start |
align-content-end | align-content: flex-end |
align-content-center | align-content: center |
align-content-between | align-content: space-between |
align-content-around | align-content: space-around |
align-content-stretch | align-content: stretch |
单个子项
| 类名 | 描述 |
|---|---|
align-self-start | align-self: flex-start |
align-self-end | align-self: flex-end |
align-self-center | align-self: center |
align-self-baseline | align-self: baseline |
align-self-stretch | align-self: stretch |
flex-grow-0 | flex-grow: 0 |
flex-grow-1 | flex-grow: 1 |
flex-shrink-0 | flex-shrink: 0 |
flex-shrink-1 | flex-shrink: 1 |
flex-fill | flex: 1 1 auto |
间距
间距类名由方向前缀和档位组成,例如 mt-2、px-4、ms-auto。基准间距是 1rem。根字号为 16px 时,各档位如下。
| 档位 | 长度 |
|---|---|
0 | 0 |
1 | 0.25rem(4px) |
2 | 0.5rem(8px) |
3 | 0.75rem(12px) |
4 | 1rem(16px) |
5 | 1.25rem(20px) |
6 | 1.5rem(24px) |
7 | 1.75rem(28px) |
8 | 2rem(32px) |
9 | 2.25rem(36px) |
10 | 2.5rem(40px) |
方向
m 是外边距,p 是内边距。
| 前缀 | 作用 |
|---|---|
m / p | 四边 |
mt / pt | 上 |
mr / pr | 右 |
mb / pb | 下 |
ml / pl | 左 |
mx / px | 左右 |
my / py | 上下 |
ms / ps | 行首(inline-start) |
me / pe | 行尾(inline-end) |
外边距
外边距除 0–10 外,还可以用 auto,以及负值 n1–n10(对应档位的相反数)。
内边距
内边距可设置 0–10。
尺寸
宽高按父元素或视口计算。
| 类名 | 描述 |
|---|---|
w-25 | width: 25% |
w-50 | width: 50% |
w-75 | width: 75% |
w-100 | width: 100% |
w-auto | width: auto |
h-25 | height: 25% |
h-50 | height: 50% |
h-75 | height: 75% |
h-100 | height: 100% |
h-auto | height: auto |
mw-100 | max-width: 100% |
mh-100 | max-height: 100% |
min-vw-100 | min-width: 100vw |
min-vh-100 | min-height: 100vh |
vw-100 | width: 100vw |
vh-100 | height: 100vh |
文字
字体大小
| 类名 | 字号 |
|---|---|
fs-small | 0.75rem(12px) |
fs-medium | 0.875rem(14px) |
fs-large | 1rem(16px) |
字号按根字号 16px 换算。
颜色
| 类名 | 含义 |
|---|---|
text-primary | 主色 |
text-success | 成功 |
text-info | 信息 |
text-warning | 警告 |
text-danger | 危险 |
text-default | 默认正文 |
text-secondary | 次级文字 |
text-tertiary | 三级文字 |
text-quaternary | 四级文字 |
text-white | 白色 |
换行与转换
| 类名 | 描述 |
|---|---|
font-italic | font-style: italic |
text-nowrap | white-space: nowrap |
text-wrap | white-space: normal |
text-truncate | 单行超出省略 |
text-break | word-wrap: break-word |
text-uppercase | text-transform: uppercase |
text-lowercase | text-transform: lowercase |
text-capitalize | text-transform: capitalize |
text-truncate 需要元素自身是 block 或 inline-block 才会出现省略号。
水平对齐
| 类名 | 描述 |
|---|---|
text-left | text-align: left |
text-right | text-align: right |
text-start | text-align: start |
text-end | text-align: end |
text-center | text-align: center |
垂直对齐
| 类名 | 描述 |
|---|---|
align-baseline | vertical-align: baseline |
align-top | vertical-align: top |
align-middle | vertical-align: middle |
align-bottom | vertical-align: bottom |
align-text-top | vertical-align: text-top |
align-text-bottom | vertical-align: text-bottom |
背景
语义色背景使用设计系统色板。*-subtle 是对应色 10% 透明度的浅底。
| 类名 | 含义 |
|---|---|
bg-primary | 主色 |
bg-success | 成功 |
bg-info | 信息 |
bg-warning | 警告 |
bg-danger | 危险 |
bg-primary-subtle | 主色浅底 |
bg-success-subtle | 成功浅底 |
bg-info-subtle | 信息浅底 |
bg-warning-subtle | 警告浅底 |
bg-danger-subtle | 危险浅底 |
bg-white | 白色 |
bg-default | 默认页面背景 |
bg-secondary | 次级背景 |
bg-transparent | 透明 |
边框
默认边框是 1px 实线,颜色为设计系统的浅灰分割线。
显示与去掉
| 类名 | 描述 |
|---|---|
border | 四边 |
border-top | 上边 |
border-right | 右边 |
border-bottom | 下边 |
border-left | 左边 |
border-0 | 去掉四边 |
border-top-0 | 去掉上边 |
border-right-0 | 去掉右边 |
border-bottom-0 | 去掉下边 |
border-left-0 | 去掉左边 |
颜色
颜色类只改 border-color,需要和上面的边框类一起用。
| 类名 | 含义 |
|---|---|
border-primary | 主色 |
border-secondary | 次级色 |
border-success | 成功 |
border-info | 信息 |
border-warning | 警告 |
border-danger | 危险 |
border-white | 白色 |
圆角
| 类名 | 描述 |
|---|---|
rounded-small | border-radius: 0.2rem |
rounded-medium | border-radius: 0.25rem |
rounded-large | border-radius: 0.3rem |
rounded-circle | border-radius: 50% |
rounded-pill | border-radius: 50rem |
rounded-top | 上左、上右圆角 |
rounded-right | 上右、下右圆角 |
rounded-bottom | 下右、下左圆角 |
rounded-left | 上左、下左圆角 |
效果
阴影
| 类名 | 描述 |
|---|---|
shadow-small | 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075) |
shadow-medium | 0 0 16px rgb(0 0 0 / 8%) |
shadow-large | 0 1rem 3rem rgba(0, 0, 0, 0.175) |
shadow-none | box-shadow: none |
指针与选择
| 类名 | 描述 |
|---|---|
cursor-pointer | cursor: pointer |
pe-none | pointer-events: none |
pe-auto | pointer-events: auto |
user-select-all | user-select: all |
user-select-auto | user-select: auto |
user-select-none | user-select: none |
激活态
active 在白名单内,可以写到 class 上。它本身不带工具类样式,用来配合组件已有的激活态样式。
示例
Display
inline 和 inline-block 会并排,block 独占一行。flex 把子项排成一行,table 配合 table-row、table-cell 按表格对齐。
溢出
容器比内容窄时,overflow-hidden 会裁掉超出的部分。
浮动
float-left 和 float-right 分别靠向两侧,正文在中间环绕。clearfix 让容器边框包住浮动的子元素。
可见性
invisible 不显示内容,但原来的位置还在。hidden 会把这块位置也拿掉。
弹性布局
justify-content-between 把子项分到两端,flex-column 改成纵向排列,flex-grow-1 占满剩余空间。
间距
外框是父元素,框内留白是内边距。mx-auto 写在定宽块上会水平居中。
尺寸
宽度按父元素计算。
水平对齐
通过 text-start、text-left、text-center、text-right、text-end 设置水平对齐。
垂直对齐
垂直对齐作用在同一行里的 inline 或 inline-block 上。外框固定高度后,顶、中、底的差别才看得出来。
背景
bg-primary 是实底,浅色字用 text-white。bg-primary-subtle 是对应色的浅底。
边框
rounded-pill 会把左右变成半圆,只保留一边时用 border-bottom 这类单边类。
阴影
三档阴影从轻到重。shadow-small 最淡,shadow-large 最重。
指针与选择
把指针移到 cursor-pointer 上会变成手型。user-select-all 点一次会选中整段,user-select-none 拖选不会选中文字。
激活态
按钮组里带 active 的按钮会用上组件自己的激活样式。