布局工具类
Tailwind 把 Flexbox 和 Grid 的属性都做成了工具类,布局基本不用写自定义 CSS。
Flex 相关
flex:display: flexflex-col:纵向排列justify-center/justify-between:主轴对齐items-center:交叉轴居中flex-1:flex: 1 等分gap-4:间距 16px
Grid 相关
grid:display: gridgrid-cols-3:三列grid-cols-[200px_1fr]:任意值(方括号语法)col-span-2:跨两列
显示与定位
hidden、block、relative、absolute、fixed、z-10 都是直接对应 CSS 属性。
代码示例
<div class="flex justify-between items-center gap-4">
<h2 class="text-xl font-bold">商品列表</h2>
<button class="bg-green-600 text-white px-4 py-2 rounded">添加</button>
</div>
<div class="grid grid-cols-3 gap-4 mt-6">
<div class="bg-gray-100 rounded-lg p-4">卡片 1</div>
<div class="bg-gray-100 rounded-lg p-4">卡片 2</div>
<div class="bg-gray-100 rounded-lg p-4">卡片 3</div>
</div>
<!-- 绝对定位居中 -->
<div class="relative h-40 bg-gray-200 rounded-lg">
<span class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">居中</span>
</div>
📚 HTML 标签速查
常用条目速查,完整版见对应教程章节。可复制代码到在线运行中测试。
| 写法 / 语法 | 作用 |
|---|---|
<h1>-<h6> | 标题,h1 最高,每页只用一个 h1 |
<p> | 段落,自动加前后间距 |
<a href=""> | 链接,href 是目标地址 |
<img src="" alt=""> | 图片,src 地址,alt 替代文字 |
<ul> / <li> | 无序列表 |
<ol> / <li> | 有序列表,数字编号 |
<dl> / <dt> / <dd> | 自定义列表:术语 + 说明 |
<table> / <tr> / <td> / <th> | 表格:行 / 单元格 / 表头 |
<form action="" method=""> | 表单,action 提交地址,method 提交方式 |
<input type=""> | 输入控件,type 有 text/password/email/number 等 |
<textarea> | 多行文本输入 |
<select> / <option> | 下拉框及选项 |
<button type="submit"> | 按钮,submit 提交表单 |
<strong> / <em> | 加粗(重要)/ 斜体(强调) |
<div> / <span> | 区块容器 / 行内容器 |
<header> <nav> <main> | 语义化:页眉 / 导航 / 主体 |
<section> <article> <aside> | 语义化:分节 / 独立内容 / 侧栏 |
<footer> | 页脚:版权、备案 |
<video> / <audio> | HTML5 视频 / 音频,加 controls 显示控制条 |
<iframe src=""> | 嵌入其他网页 |
<!-- 注释 --> | HTML 注释,不显示在页面 |
<br> / <hr> | 换行 / 水平分割线 |
<pre> | 保留空格和换行,原样显示 |
<blockquote> / <q> | 块级引用 / 行内引用 |
<figure> / <figcaption> | 图文组合及说明 |