示例工程 08-text-semantics
08-text-semantics/app/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>文本语义 · 行内元素速查</title>
<meta name="description" content="strong、em、code、mark、time 等行内语义元素的用法与边界。" />
<style>
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
padding: 32px 20px;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
line-height: 1.75;
}
.page { width: min(100%, 780px); margin: 0 auto; }
.site-header { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid #e2e8f0; }
.brand { font-weight: 700; letter-spacing: 0.14em; font-size: 13px; }
nav a { color: #2563eb; font-size: 13px; text-decoration: none; }
nav a + a { margin-left: 14px; }
main { padding: 32px 0; }
.eyebrow { margin: 0; color: #64748b; font-size: 11px; letter-spacing: 0.18em; }
h1 { margin: 6px 0 12px; font-size: clamp(30px, 6vw, 44px); line-height: 1.15; }
.lead { margin: 0 0 24px; color: #334155; font-size: 17px; }
section { margin-top: 28px; padding-top: 20px; border-top: 1px solid #e2e8f0; }
h2 { margin: 0 0 10px; font-size: 23px; }
p { margin: 0 0 12px; color: #334155; }
ul { margin: 8px 0 12px; padding-left: 24px; color: #334155; }
li + li { margin-top: 4px; }
code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, Menlo, monospace; font-size: 0.92em; }
kbd { padding: 1px 6px; border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 4px; background: #fff; font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; }
mark { padding: 0 2px; background: #fef08a; color: #422006; }
abbr[title] { text-decoration: underline dotted; cursor: help; }
table { width: 100%; margin: 10px 0; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid #e2e8f0; text-align: left; vertical-align: top; }
th { background: #f1f5f9; }
.sample { padding: 14px; border: 1px dashed #cbd5e1; border-radius: 10px; background: #fff; }
.sample p { margin: 0 0 8px; }
.sample p:last-child { margin-bottom: 0; }
pre { margin: 10px 0 0; padding: 14px; overflow-x: auto; border-radius: 10px; background: #0f172a; color: #e2e8f0; font-size: 12px; line-height: 1.7; }
pre code { padding: 0; background: none; color: inherit; }
footer { margin-top: 32px; padding-top: 16px; border-top: 1px solid #e2e8f0; color: #64748b; font-size: 12px; }
@media (max-width: 560px) {
.site-header { flex-direction: column; }
table { display: block; overflow-x: auto; }
}
</style>
</head>
<body>
<div class="page">
<header class="site-header">
<span class="brand">TEXT NOTES</span>
<nav aria-label="页内导航">
<a href="#emphasis">强调</a>
<a href="#tone">语气</a>
<a href="#code">代码</a>
<a href="#terms">术语</a>
<a href="#time">时间</a>
</nav>
</header>
<main>
<p class="eyebrow">LESSON / 08</p>
<h1>文本语义</h1>
<p class="lead">
同一段文字,语义不同,标签也不同。本章区分「强调」与「语气」、「代码」与「普通文字」、「时间」与「日期字符串」。
</p>
<section id="emphasis">
<h2>1. 强调</h2>
<p>
<strong>重要:</strong>保存前先确认文件名。这里用 <code>strong</code>,表示内容重要性。
</p>
<p>
请<em>不要</em>在演示环境删除数据。这里用 <code>em</code>,表示语气强调。
</p>
<div class="sample">
<p><strong>strong</strong> 表示重要性;<em>em</em> 表示语气重音。</p>
<p>两者可以嵌套:<strong>请<em>务必</em>先备份</strong>。</p>
</div>
</section>
<section id="tone">
<h2>2. 语气与替代样式</h2>
<ul>
<li><code>b</code>:不表示重要性的粗体,用于关键词、产品名。</li>
<li><code>i</code>:不表示强调的斜体,用于术语、外语、想法。</li>
<li><code>u</code>:拼写错误或需要标注的文字,谨慎使用。</li>
<li><code>s</code>:不再准确的内容,例如旧价格。</li>
<li><code>small</code>:附属说明、免责声明。</li>
</ul>
<p>能用 <code>strong</code>/<code>em</code> 表达语义时,不要用 <code>b</code>/<code>i</code>。</p>
</section>
<section id="code">
<h2>3. 代码与输入输出</h2>
<p>按 <kbd>Ctrl</kbd> + <kbd>S</kbd> 保存文件。</p>
<p>函数 <code>countChinese(text)</code> 返回中文字符数。</p>
<p>控制台输出 <samp>words 5017</samp>。</p>
<p>变量 <var>total</var> 从 0 开始累加。</p>
<pre><code>// 代码块用 pre > code
const total = countChinese(text);</code></pre>
</section>
<section id="terms">
<h2>4. 术语、缩写与引用</h2>
<p>
<abbr title="HyperText Markup Language">HTML</abbr> 是标记语言,
<abbr title="Cascading Style Sheets">CSS</abbr> 负责样式。
</p>
<p><dfn>语义化</dfn>指用能表达含义的标签,而不是只用 <code>div</code>。</p>
<p>规范里写:<q cite="https://example.com/spec">标题表达层级,不表达字号。</q></p>
<p>更长的引用用 <code>blockquote</code>,第 11 章会讲。</p>
</section>
<section id="time">
<h2>5. 时间与上下标</h2>
<p>课程发布于 <time datetime="2026-11-28">2026 年 11 月 28 日</time>。</p>
<p>截止时间是 <time datetime="2026-12-31T23:59">12 月 31 日 23:59</time>。</p>
<p>水分子写作 H<sub>2</sub>O,面积单位写作 m<sup>2</sup>。</p>
<p>价格从 <del>99 元</del> 调整为 <ins>79 元</ins>。</p>
<p><mark>限时</mark>提示可以用 <code>mark</code>,但不要把所有重点都标黄。</p>
</section>
</main>
<footer>
<p>示例数据,仅用于教学。</p>
</footer>
</div>
</body>
</html>