0.1.0 • Published 2 years ago

@limm/windi-css-uni v0.1.0

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
2 years ago

windi-css-uni

1️⃣ 简介

Github:https://github.com/SunSeekerX/uni-app-starter/tree/main/packages/windi-css-uni

这是一些 css 的简写类名的库,用于快速开发 uni-app。适用于 vue+nvue 文件。类名的设计参考了 windicss 的类名。

大部分效果可以参考 https://cn.windicss.org/guide/ 预览。

在写代码的过程中,写 css 是非常头疼的事情,例如:

  1. 命名;这应该是所有程序员的痛。
  2. 写 dom 不能直接写 css;html 和 css 通常不在一块,需要滑动很长才能找到 css 定义的地方。
  3. 很多重复定义;像 diaplay: flex; 这样的代码在 css 中写了太多太多

缺点也很明显

  1. 增加了一些项目根本没有用到的 css 类
  2. 可读性不好
  3. 有一定的学习成本和记忆成本

有舍有得,自行取舍。

2️⃣ 快速上手

安装

npm

npm i @limm/windi-css-uni
# or
yarn add @limm/windi-css-uni

插件市场

插件市场地址:https://ext.dcloud.net.cn/plugin?name=windi-css-uniapp

导入

推荐全部引入,开启 treeshaking 会自动裁剪没有用到的类,截至目前,css 裁剪没有方案。

${app}/App.vue style 标签最上方导入

// npm 下载
@import '@limm/windi-css-uni';

// npm 下载 - 如果使用了 stylelint
@import '@limm/windi-css-uni/src/index.scss';

// 如果是插件市场导入的
@import '@/uni_modules/windi-css-uniapp/index.scss';

关于大小

全部压缩之后大概 258KB 左右大小。nvue 下应该不到 200KB。

使用

在下面列出的类名前增加 wd- 这是全局的前缀,为了防止和其他库或者你自己定义的样式冲突。

<view class="wd-flex-row wd-justify-between wd-items-center wd-leading-34">
  <text class="wd-text-fff wd-text-16 wd-font-bold">{{ item.name }}</text>
</view>

4️⃣ class

通用

排版

样式参考说明
Font Family
font-sans!nvue
font-serif!nvue
font-mono!nvue
font-size
text-{8~48}font-size: {8-48}px;
text-{8~96}rfont-size: {8-96}rpx;
字体平滑度
antialiased-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;!nvue
subpixel-antialiased-webkit-font-smoothing: auto;-moz-osx-font-smoothing: auto;!nvue
font-style
italicfont-style: italic;
not-italicfont-style: normal;
font-weight
font-{100-900}font-weight: {100-900};步长为 100
连字符
hyphens-nonehyphens: none;!nvue
hyphens-manualhyphens: manual;!nvue
hyphens-autohyphens: auto;!nvue
行高
leading-{8-48}line-height: {8-48}px;
leading-{8-96}rline-height: {8-96}rpx;
文本对齐
text-lefttext-align: left;
text-centertext-align: center;
text-righttext-align: right;
text-justifytext-align: justify;!nvue
文本颜色
text-transparentcolor: transparent;!nvue
text-currentcolor: currentColor;!nvue
text-000text-blackcolor: #000;
text-ffftext-whitecolor: #fff;
text-{100~900}color: #{111-999};步长为 111
垂直对齐
align-baselinevertical-align: baseline;!nvue
align-topvertical-align: top;!nvue
align-middlevertical-align: middle;!nvue
align-bottomvertical-align: bottom;!nvue
align-text-topvertical-align: text-top;!nvue
align-text-bottomvertical-align: text-bottom;!nvue
文本溢出
truncatetext-overflow: ellipsis;!nvueoverflow: hidden;-o-text-overflow: ellipsis;
overflow-ellipsistext-overflow: ellipsis;!nvue-o-text-overflow: ellipsis;
overflow-clip!nvueoverflow: clip;nvuetext-overflow: clip;
行数
lines-{1~8}nvuelines: {1~8};!nvuedisplay: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: {1~8};
空格
whitespace-normalwhite-space: normal;!nvue
whitespace-nowrapwhite-space: nowrap;!nvue
whitespace-prewhite-space: pre;!nvue
whitespace-pre-linewhite-space: pre-line;!nvue
whitespace-pre-wrapwhite-space: pre-wrap;!nvue
断字
break-normaloverflow-wrap: normal;word-break: normal;!nvue
break-wordsoverflow-wrap: break-word;!nvue
break-all!nvue: word-break: break-all;!nvue

背景

样式参考说明
背景固定
bg-fixedbackground-attachment: fixed;!nvue
bg-localbackground-attachment: local;!nvue
bg-scrollbackground-attachment: scroll;!nvue
背景裁剪
bg-clip-borderbackground-clip: border-box;!nvue
bg-clip-paddingbackground-clip: padding-box;!nvue
bg-clip-contentbackground-clip: content-box;!nvue
背景颜色
bg-transparentbackground-color: transparent;
bg-currentbackground-color: currentColor;!nvue
bg-fffbg-whitebackground-color: #fff;
bg-000bg-blackbackground-color: #000;
bg-{111-999}background-color: #{111-999};步长为 111
背景图像位置
bg-bottombackground-position: bottom;!nvue
bg-centerbackground-position: center;!nvue
bg-leftbackground-position: left;!nvue
bg-left-bottombackground-position: left bottom;!nvue
bg-left-topbackground-position: left top;!nvue
bg-rightbackground-position: right;!nvue
bg-right-bottombackground-position: right bottom;!nvue
bg-right-topbackground-position: right top;!nvue
bg-topbackground-position: top;!nvue
背景图像重复
bg-repeatbackground-repeat: repeat;!nvue
bg-repeat-xbackground-repeat: repeat-x;!nvue
bg-repeat-ybackground-repeat: repeat-y;!nvue
bg-repeat-roundbackground-repeat: round;!nvue
bg-repeat-spacebackground-repeat: space;!nvue
背景图像大小
bg-autobackground-size: auto;!nvue
bg-coverbackground-size: cover;!nvue
bg-containbackground-size: contain;!nvue
背景图像原点
bg-origin-borderbackground-origin: border-box;!nvue
bg-origin-paddingbackground-origin: padding-box;!nvue
bg-origin-contentbackground-origin: content-box;!nvue

边框

样式参考说明
边框圆角
rounded-noneborder-radius: 0px;
rounded-fullborder-radius: 9999px;
rounded-{0~32}border-radius: {0~32}px;
rounded-{0~64}rborder-radius: {0~64}rpx;
rounded-{0~100}pborder-radius: {0~100}%;
边框宽度
border-{0-10}border-width: {0-10}px;
border-{0-20}rborder-width: {0-20}rpx;
border-top-{0-10}border-top-width: {0-10}px;
border-top-{0-20}rborder-top-width: {0-20}rpx;
border-right-{0-10}border-right-width: {0-10}px;
border-right-{0-20}rborder-right-width: {0-20}rpx;
border-bottom-{0-10}border-bottom-width: {0-10}px;
border-bottom-{0-20}rborder-bottom-width: {0-20}rpx;
border-left-{0-10}border-left-width: {0-10}px;
border-left-{0-20}rborder-left-width: {0-20}rpx;
边框颜色
border-transparentborder-color: transparent;
border-currentborder-color: currentColor;!nvue
border-fffborder-whiteborder-color: #fff;
border-000border-blackborder-color: #000;
border-{111-999}border-color: #{111-999};
边框样式
border-solidborder-style: solid;
border-dashedborder-style: dashed;
border-dottedborder-style: dotted;
border-doubleborder-style: double;!nvue
border-noneborder-style: none;!nvue

特效

样式参考说明
Opacity
opacity-{0~100}opacity: {0~100};步长为 5

布局

Display

样式参考说明
块级元素
blockdisplay: block;!nvue
inline-blockdisplay: inline-block;!nvue
inlinedisplay: inline;!nvue
contentsdisplay: contents;!nvue
hiddendisplay: none;!nvue
visiblevisibility: visible;!nvue
invisiblevisibility: hidden;!nvue

Flexbox

样式参考说明
Flex
flexdisplay: flex !important;!nvue
flex-centernvue: justify-content: center !important;align-items: center !important;!nvue: display: flex !important;justify-content: center !important;align-items: center !important;
Flex 方向
flex-rowflex-direction: row !important;
flex-row-reverseflex-direction: row-reverse !important;
flex-colflex-direction: column !important;
flex-col-reverseflex-direction: column-reverse !important;
Flex Wrap
flex-wrapflex-wrap: wrap !important;
flex-wrap-reverseflex-wrap: wrap-reverse !important;
flex-nowrapflex-wrap: nowrap !important;
Flex Stretch
flex-autoflex: 1 1 auto;!nvue
flex-initialflex: 0 1 auto;!nvue
flex-noneflex: none;!nvue
flex-{1~16}flex: {1-16} !important;
Flex Grow
flex-grow-0flex-grow: 0;!nvue
flex-growflex-grow: 1;!nvue
Flex Shrink
flex-shrink-0flex-shrink: 0;!nvue
flex-shrinkflex-shrink: 1;!nvue

Posiioning

样式参考说明
Order
order-firstorder: -9999;!nvue
order-lastorder: 9999;!nvue
order-noneorder: 0;!nvue
order-{0~16}order: {0~16};!nvue
Justify Content
justify-startjustify-content: flex-start !important;
justify-endjustify-content: flex-end;!important
justify-centerjustify-content: center !important;
justify-betweenjustify-content: space-between !important;
justify-aroundjustify-content: space-around;!nvue
justify-evenlyjustify-content: space-evenly;!nvue
Justify Items
justify-items-autojustify-items: auto;
justify-items-startjustify-items: start;
justify-items-endjustify-items: end;
justify-self-centerjustify-self: center;
justify-self-stretchjustify-self: stretch;
Align Items
items-startalign-items: flex-start !important;
items-endalign-items: flex-end;!important
items-centeralign-items: center;!important
items-baselinealign-items: baseline;!nvue
items-stretchalign-items: stretch !important;
Align Self
self-autoalign-self: auto;!nvue
self-startalign-self: flex-start;!nvue
self-endalign-self: flex-end;!nvue
self-centeralign-self: center;!nvue
self-stretchalign-self: stretch;!nvue
Place Content
place-content-centerplace-content: center;!nvue
place-content-startplace-content: start;!nvue
place-content-endplace-content: end;!nvue
place-content-betweenplace-content: space-between;!nvue
place-content-aroundplace-content: space-around;!nvue
place-content-evenlyplace-content: space-evenly;!nvue
place-content-stretchplace-content: stretch;!nvue
Place Items
place-items-autoplace-items: auto;!nvue
place-items-startplace-items: start;!nvue
place-items-endplace-items: end;!nvue
place-items-centerplace-items: center;!nvue
place-items-stretchplace-items: stretch;!nvue
Place Self
place-self-autoplace-self: auto;!nvue
place-self-startplace-self: start;!nvue
place-self-endplace-self: end;!nvue
place-self-centerplace-self: center;!nvue
place-self-stretchplace-self: stretch;!nvue
Position
staticposition: static;!nvue
fixedposition: fixed !important;
absoluteposition: absolute !important;
relativeposition: relative !important;
stickyposition: sticky !important;
Top / Right / Bottom / Left
inset-0top: 0px;right: 0px;bottom: 0px;left: 0px;
inset-pxtop: 1px;right: 1px;bottom: 1px;left: 1px;
inset-autotop: auto;right: auto;bottom: auto;left: auto;
inset-fulltop: 100%;right: 100%;bottom: 100%;left: 100%;
top-{0-50}top: {0-50}px;
top-{1-100}rtop: {1-100}rpx;
right-{0-50}right: {0-50}px;
right-{1-100}rright: {1-100}rpx;
bottom-{0-50}bottom: {0-50}px;
bottom-{1-100}rbottom: {1-100}rpx;
left-{0-50}left: {0-50}px;
left-{1-100}rleft: {1-100}rpx;
Floats
float-rightfloat: right;!nvue
float-leftfloat: left;!nvue
float-nonefloat: none;!nvue
Clear
clear-rightclear: right;!nvue
clear-leftclear: left;!nvue
clear-bothclear: both;!nvue
clear-noneclear: none;!nvue
Object Fit
object-containobject-fit: contain;!nvue
object-coverobject-fit: cover;!nvue
object-fillobject-fit: fill;!nvue
object-noneobject-fit: none;!nvue
object-scale-downobject-fit: scale-down;!nvue
Object Position
object-bottomobject-position: bottom;!nvue
object-centerobject-position: center;!nvue
object-leftobject-position: left;!nvue
object-left-bottomobject-position: left bottom;!nvue
object-left-topobject-position: left top;!nvue
object-rightobject-position: right;!nvue
object-right-bottomobject-position: right bottom;!nvue
object-right-topobject-position: right top;!nvue
object-topobject-position: top;!nvue
Z-Index
z-autoz-index: auto;!nvue
z-{0~16}z-index: {0~16} !important;

尺寸

样式参考说明
width
w-{0~750}rwidth: {0~750}rpx;
w-{0~500}width: {0~500}px;
w-{0~100}pwidth: {0~100}%;
height
h-{0~750}rheight: {0~750}rpx;
h-{0~500}height: {0~500}px;
h-{0~100}pheight: {0~100}%;
Box Sizing
box-borderbox-sizing: border-box;
box-contentbox-sizing: content-box;

间隔

样式参考说明
Padding
pt-{0~100}padding-top: {0~100}px;
pt-{1~200}rpadding-top: {1~200}rpx;
pr-{0~100}padding-right: {0~100}px;
pr-{1~200}rpadding-right: {1~200}rpx;
pb-{0~100}padding-bottom: {0~100}px;
pb-{1~200}rpadding-bottom: {1~200}rpx;
pl-{0~100}padding-left: {0~100}px;
pl-{1~200}rpadding-left: {1~200}rpx;
p-{0-100}padding: {0~100}px;
p-{1-200}rpadding: {1~200}rpx;
px-{0-100}padding-right: {0~100}px;padding-left: {0~100}px;
px-{1-200}rpadding-right: {1~200}rpx;padding-left: {1~200}rpx;
py-{0-100}padding-top: {0~100}px;padding-bottom: {0~100}px;
py-{1-200}rpadding-top: {1~200}rpx;padding-bottom: {1~200}rpx;
Margin
mt-{0~100}margin-top: {0~100}px;
mt-{1~200}rmargin-top: {1~200}rpx;
mr-{0~100}margin-right: {0~100}px;
mr-{1~200}rmargin-right: {1~200}rpx;
mb-{0~100}margin-bottom: {0~100}px;
mb-{1~200}rmargin-bottom: {1~200}rpx;
ml-{0~100}margin-left: {0~100}px;
ml-{1~200}rmargin-left: {1~200}rpx;
m-{0-100}margin: {0~100}px;
m-{1-200}rmargin: {1~200}rpx;
mx-{0-100}margin-right: {0~100}px;margin-left: {0~100}px;
mx-{1-200}rmargin-right: {1~200}rpx;margin-left: {1~200}rpx;
my-{0-100}margin-top: {0~100}px;margin-bottom: {0~100}px;
my-{1-200}rmargin-top: {1~200}rpx;margin-bottom: {1~200}rpx;
mx-automargin-right: auto;margin-left: auto;

5️⃣ 问题?

  1. 为什么没有 max-widthmin-widthmax-heightmin-height 等类?

    付出 > 收益,性价比不高,项目中用到的地方不多。增加之后文件增大了 100 多 kb。没有必要。

6️⃣ 更新日志(CHANGELOG)

0.1.0

  • 文档修正

0.0.8

  • 文档增加插件市场下载方式安装使用,支持 uni_modules

0.0.7

  • 移除 nvue 下的断字相关的类,避免警告
    • break-normal
    • break-words
    • break-all

0.0.6

  • 文档颜色描述修正

0.0.5

  • 修正文本溢出行数无效

0.0.4

  • 增加文本溢出功能类
  • 增加 nvue 下 lines-{1~8} 功能类

0.0.3

  • 文档颜色描述修正
  • 增加边框颜色 border-black
  • 增加边框颜色 border-{000~999}

0.0.2

  • 增加背景色 bg-{000~999}
  • 增加背景色 bg-black
  • 增加文字颜色 text-fff、text-white
  • 增加文字颜色 text-black

0.0.1

  • 第一个可用版本
0.1.0

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago