安装
Tailwind CSS入门
Tailwind CSS 的工作原理是扫描所有 HTML 文件、JavaScript 组件和任何其他模板以查找类名,生成相应的样式,然后将它们写入静态 CSS 文件。
它快速、灵活、可靠——零运行时。
Installing Tailwind CLI
The simplest and fastest way to get up and running with Tailwind CSS from scratch is with the Tailwind CLI tool. The CLI is also available as a standalone executable if you want to use it without installing Node.js.

安装 Tailwind CSS
Install
tailwindcss
via npm, and create yourtailwind.config.js
file.Terminalnpm install -D tailwindcssnpx tailwindcss init
配置模板路径
Add the paths to all of your template files in your
tailwind.config.js
file.tailwind.config.js/** @type {import('tailwindcss').Config} */ module.exports = { content: ["./src/**/*.{html,js}"], theme: { extend: {}, }, plugins: [], }
将Tailwind指令添加到CSS
Add the
@tailwind
directives for each of Tailwind’s layers to your main CSS file.src/input.css@tailwind base; @tailwind components; @tailwind utilities;
启动Tailwind CLI构建过程
Run the CLI tool to scan your template files for classes and build your CSS.
Terminalnpx tailwindcss -i ./src/input.css -o ./src/output.css --watch
开始在HTML中使用Tailwind
Add your compiled CSS file to the
<head>
and start using Tailwind’s utility classes to style your content.src/index.html<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="./output.css" rel="stylesheet"> </head> <body> <h1 class="text-3xl font-bold underline"> Hello world! </h1> </body> </html>
下一步阅读内容
熟悉Tailwind CSS与编写传统CSS不同的一些核心概念。