Skip to content

Styles ​

Native UI 只渲染白名单里的工具类。在任意 nx-* 组件上写这些类名,组件会使用白名单里的类。Angular 模板用 class,React 用 className。

使用 ​

html
<nx-box class="flex p-3 bg-default rounded-medium">
  <nx-text class="text-secondary fs-small">Styles</nx-text>
</nx-box>
tsx
<NxBox className="flex p-3 bg-default rounded-medium">
  <NxText className="text-secondary fs-small">Styles</NxText>
</NxBox>

布局 ​

控制元素的显示方式、定位、浮动、溢出、可见性和层叠。

Display ​

类名描述
inlinedisplay: inline
blockdisplay: block
inline-blockdisplay: inline-block
flexdisplay: flex
inline-flexdisplay: inline-flex
tabledisplay: table
table-rowdisplay: table-row
table-celldisplay: table-cell
hiddendisplay: none

hidden 会从布局中拿掉元素。只想保留占位、不显示内容时用下面的 invisible。

定位 ​

类名描述
staticposition: static
relativeposition: relative
absoluteposition: absolute
fixedposition: fixed
stickyposition: sticky

溢出 ​

auto、visible、hidden、scroll 可以作用在两个方向,或只作用在水平、垂直方向。

类名描述
overflow-autooverflow: auto
overflow-visibleoverflow: visible
overflow-hiddenoverflow: hidden
overflow-scrolloverflow: scroll
overflow-x-autooverflow-x: auto
overflow-x-visibleoverflow-x: visible
overflow-x-hiddenoverflow-x: hidden
overflow-x-scrolloverflow-x: scroll
overflow-y-autooverflow-y: auto
overflow-y-visibleoverflow-y: visible
overflow-y-hiddenoverflow-y: hidden
overflow-y-scrolloverflow-y: scroll

浮动 ​

类名描述
float-leftfloat: left
float-rightfloat: right
float-nonefloat: none
clearfix清除子元素浮动

可见性 ​

类名描述
visiblevisibility: visible
invisiblevisibility: hidden

层叠 ​

类名描述
z-n1z-index: -1
z-0z-index: 0
z-1z-index: 1
z-2z-index: 2
z-3z-index: 3

弹性布局 ​

这些类名作用在已经是 flex 容器或 flex 子项的元素上。容器本身用布局里的 flex 或 inline-flex。

方向与换行 ​

类名描述
flex-rowflex-direction: row
flex-row-reverseflex-direction: row-reverse
flex-columnflex-direction: column
flex-column-reverseflex-direction: column-reverse
flex-wrapflex-wrap: wrap
flex-nowrapflex-wrap: nowrap
flex-wrap-reverseflex-wrap: wrap-reverse

主轴对齐 ​

类名描述
justify-content-startjustify-content: flex-start
justify-content-endjustify-content: flex-end
justify-content-centerjustify-content: center
justify-content-betweenjustify-content: space-between
justify-content-aroundjustify-content: space-around

交叉轴对齐 ​

类名描述
align-items-startalign-items: flex-start
align-items-endalign-items: flex-end
align-items-centeralign-items: center
align-items-baselinealign-items: baseline
align-items-stretchalign-items: stretch

多行对齐 ​

类名描述
align-content-startalign-content: flex-start
align-content-endalign-content: flex-end
align-content-centeralign-content: center
align-content-betweenalign-content: space-between
align-content-aroundalign-content: space-around
align-content-stretchalign-content: stretch

单个子项 ​

类名描述
align-self-startalign-self: flex-start
align-self-endalign-self: flex-end
align-self-centeralign-self: center
align-self-baselinealign-self: baseline
align-self-stretchalign-self: stretch
flex-grow-0flex-grow: 0
flex-grow-1flex-grow: 1
flex-shrink-0flex-shrink: 0
flex-shrink-1flex-shrink: 1
flex-fillflex: 1 1 auto

间距 ​

间距类名由方向前缀和档位组成,例如 mt-2、px-4、ms-auto。基准间距是 1rem。根字号为 16px 时,各档位如下。

档位长度
00
10.25rem(4px)
20.5rem(8px)
30.75rem(12px)
41rem(16px)
51.25rem(20px)
61.5rem(24px)
71.75rem(28px)
82rem(32px)
92.25rem(36px)
102.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-25width: 25%
w-50width: 50%
w-75width: 75%
w-100width: 100%
w-autowidth: auto
h-25height: 25%
h-50height: 50%
h-75height: 75%
h-100height: 100%
h-autoheight: auto
mw-100max-width: 100%
mh-100max-height: 100%
min-vw-100min-width: 100vw
min-vh-100min-height: 100vh
vw-100width: 100vw
vh-100height: 100vh

文字 ​

字体大小 ​

类名字号
fs-small0.75rem(12px)
fs-medium0.875rem(14px)
fs-large1rem(16px)

字号按根字号 16px 换算。

颜色 ​

类名含义
text-primary主色
text-success成功
text-info信息
text-warning警告
text-danger危险
text-default默认正文
text-secondary次级文字
text-tertiary三级文字
text-quaternary四级文字
text-white白色

换行与转换 ​

类名描述
font-italicfont-style: italic
text-nowrapwhite-space: nowrap
text-wrapwhite-space: normal
text-truncate单行超出省略
text-breakword-wrap: break-word
text-uppercasetext-transform: uppercase
text-lowercasetext-transform: lowercase
text-capitalizetext-transform: capitalize

text-truncate 需要元素自身是 block 或 inline-block 才会出现省略号。

水平对齐 ​

类名描述
text-lefttext-align: left
text-righttext-align: right
text-starttext-align: start
text-endtext-align: end
text-centertext-align: center

垂直对齐 ​

类名描述
align-baselinevertical-align: baseline
align-topvertical-align: top
align-middlevertical-align: middle
align-bottomvertical-align: bottom
align-text-topvertical-align: text-top
align-text-bottomvertical-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-smallborder-radius: 0.2rem
rounded-mediumborder-radius: 0.25rem
rounded-largeborder-radius: 0.3rem
rounded-circleborder-radius: 50%
rounded-pillborder-radius: 50rem
rounded-top上左、上右圆角
rounded-right上右、下右圆角
rounded-bottom下右、下左圆角
rounded-left上左、下左圆角

效果 ​

阴影 ​

类名描述
shadow-small0 0.125rem 0.25rem rgba(0, 0, 0, 0.075)
shadow-medium0 0 16px rgb(0 0 0 / 8%)
shadow-large0 1rem 3rem rgba(0, 0, 0, 0.175)
shadow-nonebox-shadow: none

指针与选择 ​

类名描述
cursor-pointercursor: pointer
pe-nonepointer-events: none
pe-autopointer-events: auto
user-select-alluser-select: all
user-select-autouser-select: auto
user-select-noneuser-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 的按钮会用上组件自己的激活样式。

举报邮箱:abuse@worktile.com