相关文档
安装
npm install -D tailwindcss postcss autoprefixer
可能会出现以下问题(没有最好):
初始化配置文件
npx tailwindcss init -p
编辑 tailwind.config.js 文件
通过配置文件可以定制自己的CSS样式
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
创建 src/theme/tailwind.css
@tailwind base;
@tailwind components;
@tailwind utilities;
在 main.js 中导入
import '@/theme/tailwind.css'
使用
- 第一种方式
<template>
<div class="text-[#008c8c] text-[20px] font-bold">
Vue3-App
</div>
</template>
- 第二种方式
<template>
<div class="title">
Vue3-App
</div>
</template>
<style>
.title {
@apply text-[#008c8c] text-[20px] font-bold;
}
</style>
去除提示 Unknown at rule @apply css(unknownAtRules)
- 创建.vscode
- 创建 settings.json
- 创建 tailwind.json
- 编写 settings.json
{
"css.customData": [".vscode/tailwind.json"]
}
- 编写 tailwind.json
{
"version": 1.1,
"atDirectives": [
{
"name": "@tailwind",
"description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.",
"references": [
{
"name": "Tailwind Documentation",
"url": "https://tailwindcss.com/docs/functions-and-directives#tailwind"
}
]
},
{
"name": "@apply",
"description": "Use the `@apply` directive to inline any existing utility classes into your own custom CSS. This is useful when you find a common utility pattern in your HTML that you’d like to extract to a new component.",
"references": [
{
"name": "Tailwind Documentation",
"url": "https://tailwindcss.com/docs/functions-and-directives#apply"
}
]
},
{
"name": "@responsive",
"description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css\n@responsive {\n .alert {\n background-color: #E53E3E;\n }\n}\n```\n",
"references": [
{
"name": "Tailwind Documentation",
"url": "https://tailwindcss.com/docs/functions-and-directives#responsive"
}
]
},
{
"name": "@screen",
"description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css\n@screen sm {\n /* ... */\n}\n```\n…gets transformed into this:\n```css\n@media (min-width: 640px) {\n /* ... */\n}\n```\n",
"references": [
{
"name": "Tailwind Documentation",
"url": "https://tailwindcss.com/docs/functions-and-directives#screen"
}
]
},
{
"name": "@variants",
"description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css\n@variants hover, focus {\n .btn-brand {\n background-color: #3182CE;\n }\n}\n```\n",
"references": [
{
"name": "Tailwind Documentation",
"url": "https://tailwindcss.com/docs/functions-and-directives#variants"
}
]
}
]
}
- 重启 vscode, 不然不会生效