UnoCSS 是一个即时的原子化 CSS 引擎,旨在灵活和可扩展。核心是不拘一格的,所有的 CSS 工具类都是通过预设提供的。再也不用为了取一个 classname 类名而烦恼了。

这里以 Vue3 + Vite 为例
vite.config.js 中配置uno.config.jts 配置文件:main.js 中引入常用值:
w-0:width: 0w-1:width: 0.25remh-100px: height: 100pxh--10px: height: -10pxh-full: height: 100%min-w-screen: min-width: 100vw常用值:
rounded-none:border-radius: 0;rounded-l:border-top-left-radius: 0.25rem; border-bottom-left-radius: 0.25rem;rounded-full: border-radius: 9999px;border-0: border-width: 0;b-0: border-width: 0;b-1: border-width: 1px;b-b-1: border-bottom-width: 1px;b-solid: border-style: solid;b-#f00: border-color: #f00;b-rd: border-radius: 0.25rem;b-rounded: border-radius: 0.25rem;b-rd-6px: border-radius: 6px;b-rd-full: border-radius: 9999px;b-rd-50%: border-radius: 50%;常用值:
m-0:margin: 0;mx-0: margin-left: 0; margin-right: 0;py-10px: padding-top: 10px; padding-bottom: 10px;p-10px: padding: 10px;p--20px: padding: -20px;常用值:
flex: display: flex;flex-wrap: flex-wrap: wrap;flex-row: flex-direction: row;flex-col: flex-direction: column;flex-justify-between: justify-content: space-between;flex-justify-center: justify-content: center;flex-items-center: align-items: center;常用值:
overflow-hidden: overflow: hidden;overflow-auto: overflow: auto;overflow-scroll: overflow: scroll;overflow-x-auto: overflow-x: auto;常用值:
absolute: position: absolute;position-absolute: position: absolute;position-fixed: position: fixed;position-relative: position: relative;left-0: left: 0;top-5px: top: 5px;z-0: z-index: 0;z-100: z-index: 100;常用值:
hover-block: display: block;hover-text-pink: color: pink;常用值:
block: display: block;inline-block: display: inline-block;flex: display: flex;hidden: display: none;UnoCSS 与 TailwindCSS 类似,但是它更加轻量级,使用体验更好,而且它的中文文档也很完善,可以说是 TailwindCSS 的一个很好的替代品。
尤其是 UnoCSS 的自定义 classname 类名功能,不用 [] 包裹,更加直观,例如:
参考文档
欢迎访问:天问博客