Tailwind CSS - Rapidly build modern websites without ever leaving your HTML.
你不需要先学 CSS,只要理解这 10 个高频类名:
| Tailwind 类 | 含义 |
|---|---|
| p-4 | 内边距 padding |
| m-4 | 外边距 margin |
| text-xl | 字体大小 |
| font-bold | 加粗 |
| bg-blue-500 | 背景颜色 |
| text-white | 字体颜色白色 |
| rounded-xl | 圆角 |
| shadow | 阴影 |
| flex | 开启弹性布局 |
| items-center | 垂直居中 |
📌 练习:做一个按钮
<button class="px-4 py-2 bg-blue-500 text-white rounded-lg">按钮</button>
数字 × 4 ≈ 像素值; p-4 代表 padding 16px
Tailwind 的字体大小也有一套固定刻度,text-xl 对应的是 1.25rem(≈ 20px)。
| 类名 | rem | 像素(默认) |
|---|---|---|
| text-xs | 0.75rem | 12px |
| text-sm | 0.875rem | 14px |
| text-base | 1rem | 16px |
| text-lg | 1.125rem | 18px |
| text-xl | 1.25rem | 20px |
| text-2xl | 1.5rem | 24px |
| text-3xl | 1.875rem | 30px |
| text-4xl | 2.25rem | 36px |
| text-5xl | 3rem | 48px |
你会发现:
Tailwind 的所有字体都是在 16px 基础上按固定比例扩展。
CSS 最难的是布局,Tailwind 让它变简单。
重点类名:
| 类名 | 含义 |
|---|---|
| flex | 横向排列 |
| flex-col | 纵向排列 |
| justify-between | 两端对齐 |
| items-center | 垂直居中 |
| gap-4 | 元素间距 |
📌 练习:做一个 Header