unocss和tailwindcss css原子引擎

news/2024/10/21 10:18:36/

第一种tailwindcss:

tailwindcss官网
https://tailwindcss.com/docs/grid-column
在这里插入图片描述

基本介绍及优点分析

Tailwind CSS 中文文档 - 无需离开您的HTML,即可快速建立现代网站

在这里插入图片描述

PostCss 处理 Tailwind Css 基本流程

PostCSS - 是一个用 JavaScript 工具和插件来转换 CSS 代码的工具 | PostCSS中文网
在这里插入图片描述

在 vscode 中,安装 Tailwind Css 插件,增加代码提示

初始化项目

npm init vue@latest

安装 Tailwind Css

npm install -D tailwindcss@latest postcss@latest autoprefixer@latest

执行命令,生成两个配置文件

  • postcss.config.js
  • tailwind.config.js

npx tailwindcss init -p

配置文档参考:配置 - Tailwind CSS 中文文档

修改配置文件 tailwind.config.js

2.6


module.exports = {purge: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],theme: {extend: {},},plugins: [],**```
3.0版本**```cppmodule.exports = {content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],theme: {extend: {},},plugins: [],
}

创建 index.css,并在 main.ts 中引入

创建 index.css

@tailwind base;
@tailwind components;
@tailwind utilities;

第二种unocss

unocss官网
https://unocss.dev/config/rules
在这里插入图片描述
unocss:最好配合vite去构建文件
操作搜索页面:
在这里插入图片描述

在这里插入图片描述

unocss 原子化

重新构想原子化CSS - 知乎
在这里插入图片描述

unocss 原子化参考资料

由于个人感觉此模块在实际项目中应用很少,所以不做记录,但是为了以防万一,先记下来之前看过的文章及视频,讲的非常清晰,给大佬点赞~~
小满Vue3(第三十七章 unoCss原子化)_哔哩哔哩_bilibili
小满Vue3第三十七章(unocss原子化)_小满zs的博客-CSDN博客
在这里插入图片描述

unocss配置(案例)

安装依赖

npm i --save unocss,@unocss/reset

mian.ts中引入
import '@unocss/reset/tailwind.css' //初始化css
import 'uno.css'//引入unocss
新建unocss.config.ts

可 查看配置文档
在这里插入图片描述

import {defineConfig,presetAttributify,presetUno,presetIcons,
} from "unocss";
export default defineConfig({//预设:m-3 p-3presets: [presetUno(),presetAttributify(),presetIcons({ scale: 1.2, warn: true }),],//快捷方式shortcuts: [["wh-full", "w-full h-full"],["f-c-c", "flex justify-center items-center"],["flex-col", "flex flex-col"],["text-ellipsis", "truncate"],["icon-btn","text-16 inline-block cursor-pointer select-none opacity-75 transition duration-200 ease-in-out hover:opacity-100 hover:text-primary !outline-none",],],//正则rules: [[/^bc-(.+)$/, ([, color]) => ({ "border-color": `#${color}` })],["card-shadow",{"box-shadow":"0 1px 2px -2px #00000029, 0 3px 6px #0000001f, 0 5px 12px 4px #00000017",},],],theme: {colors: { primary: "var(--primary-color)", dark_bg: "var(--dark-bg)" },},
});
vite.config.ts中注入
import unocss from 'unocss/vite'plugins: [unocss(),react()]//unocss一定要放react之前
处理unocss写入标签报错

src目录下新建 html.d.ts

//react
import type {AttributifyAttributes} from '@unocss/preset-attributify'
declare module "react"{interface HTMLAttributes<T> extends AttributifyAttributes {}//tsx标签写uno不报错
}
//vue
import type {AttributifyAttributes} from '@unocss/preset-attributify'
declare module "@vue/runtime-dom"{interface HTMLAttributes extends AttributifyAttributes {}//tsx标签写uno不报错
}

在这里插入图片描述
unocss的插件

配置2(案例)

在这里插入图片描述
在这里插入图片描述

unocss配置
Vue3 学习笔记 —— scoped、tailwind、unocss 原子化、Vue3 样式新特性
重新构想原子化CSS


http://www.ppmy.cn/news/1184037.html

相关文章

拉扎维模拟CMOS集成电路设计西交张鸿老师课程P2~5视频学习记录

目录 p2 p3 p4 p5 --------------------------------------------------------------------------------------------------------------------------------- p2 -----------------------------------------------------------------------------------------------------…

YOLOv5算法 | 万字长文带你深度解析yolov5s.yaml配置文件

前言&#xff1a;Hello大家好&#xff0c;我是小哥谈。配置文件yolov5s.yaml在YOLOv5模型训练过程中发挥着至关重要的作用&#xff0c;属于初学者必知必会的文件&#xff01;在YOLOv5-6.0版本源码中&#xff0c;配置了5种不同大小的网络模型&#xff0c;分别是YOLOv5n、YOLOv5s…

Element 多个Form表单 同时验证

一、背景 在一个页面中需要实现两个Form表单&#xff0c;并在页面提交时需要对两个Form表单进行校验&#xff0c;两个表单都校验成功时才能提交 所用技术栈&#xff1a;Vue2Element UI 二、实现效果 三、多个表单验证 注意项&#xff1a; 两个form表单&#xff0c;每个表单上…

机器视觉3D项目评估的基本要素及测量案例分析

目录 一. 检测需求确认 1、产品名称&#xff1a;【了解是什么产品上的零件&#xff0c;功能是什么】 2、*产品尺寸&#xff1a;【最大兼容尺寸】 3、*测量项目&#xff1a;【确认清楚测量点位】 4、*精度要求&#xff1a;【若客户提出的精度值过大或者过小&#xff0c;可以和客…

tomcat9~10猫闪退个人经验

java版本17与8 8版本有jre&#xff0c;java17没有jre 所以在java8版本中将jre和jdk路径一同添加环境是不会出现闪退的&#xff0c;tomcat9没有闪退 但是在10就闪退了&#xff0c;因为java版本太低 java17没有jre&#xff0c;但是可以通过一种方法添加jre到java17的目录 完…

二叉树三种遍历的递归与非递归写法

目录 ​编辑 一&#xff0c;前序遍历 题目接口&#xff1a; 递归解法&#xff1a; 非递归解法&#xff1a; 二&#xff0c;中序遍历 题目接口&#xff1a; 递归解法&#xff1a; 非递归写法&#xff1a; 三&#xff0c;后序遍历 题目接口&#xff1a; 递归解法&…

深入浅出排序算法之基数排序

目录 1. 前言 1.1 什么是基数排序⭐⭐⭐ 1.2 执行流程⭐⭐⭐⭐⭐ 2. 代码实现⭐⭐⭐ 3. 性能分析⭐⭐ 3.1 时间复杂度 3.2 空间复杂度 1. 前言 一个算法&#xff0c;只有理解算法的思路才是真正地认识该算法&#xff0c;不能单纯记住某个算法的实现代码&#xff01; 1.…

基于spring-boot框架,监听nacos配置变化(比如运行中改变日志级别)

背景 如果想在运行过程中想基于nacos数据变更做一些业务&#xff0c;比如想在运行过程中变更日志的级别&#xff0c;那么我们可以扩展nacos的监听。 步骤 定义一个配置类&#xff0c;用NacosConfigListener标记需要触发的方法&#xff0c;并用dataId标记需要监听的文件。如下…