<!-- 传统 CSS -->
<div class="card"></div>
<style>.card{ padding:1rem; bg:white; rounded-lg }</style>
<!-- Tailwind 直接写 -->
<div class="p-4 bg-white rounded-lg"></div>
tailwind.config.js 一行代码就能全局统一风格。<!-- 手机100%宽度,平板50%,电脑25% -->
<div class="w-full md:w-1/2 lg:w-1/4"></div>
sm:小屏幕md:平板lg:笔记本xl:大屏2xl:超大屏<button class="bg-blue-500 hover:bg-blue-600 focus:ring active:bg-blue-700">
按钮
</button>
hover/focus/active/disabled/dark(暗黑模式)等。| 样式 | 类名 | 含义 |
|---|---|---|
| 内边距 | p-4 |
padding: 1rem |
| 外边距 | m-2 |
margin: 0.5rem |
| 背景色 | bg-red-500 |
background: red |
| 文字大小 | text-lg |
font-size: large |
| 文字颜色 | text-white |
color: white |
| 圆角 | rounded-lg |
border-radius |
| 阴影 | shadow-md |
box-shadow |
| 弹性布局 | flex items-center |
flex + 垂直居中 |
| 宽度 | w-1/2 |
width: 50% |
<div class="max-w-sm mx-auto p-6 bg-white rounded-lg shadow-md">
<h2 class="text-xl font-bold text-gray-800">Tailwind 卡片</h2>
<p class="mt-2 text-gray-600">实用优先 CSS 框架,快速开发页面</p>
<button class="mt-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
点击查看
</button>
</div>
<script src="https://cdn.tailwindcss.com"></script>
创建时间
2026.03.13
更新时间
2026.03.23
访问量
34