示例工程 02-document-structure
02-document-structure/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>文档骨架 · HTML 笔记</title>
<meta name="description" content="doctype、html、head、body 四层结构的最小示例。" />
<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%, 760px); 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 { color: #64748b; font-size: 11px; letter-spacing: 0.18em; }
h1 { margin: 6px 0 12px; font-size: clamp(30px, 6vw, 46px); line-height: 1.1; }
.lead { margin: 0 0 20px; color: #334155; font-size: 17px; }
section { margin-top: 24px; padding: 20px; border: 1px solid #e2e8f0; border-radius: 14px; background: #fff; }
h2 { margin: 0 0 10px; font-size: 20px; }
p { margin: 0 0 10px; color: #334155; }
ol, ul { margin: 8px 0 0; padding-left: 22px; 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; }
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; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.box { padding: 14px; border: 1px solid #e2e8f0; border-radius: 10px; background: #f8fafc; }
.box h3 { margin: 0 0 6px; font-size: 15px; }
footer { padding-top: 18px; border-top: 1px solid #e2e8f0; color: #64748b; font-size: 12px; }
@media (max-width: 560px) {
.site-header { flex-direction: column; }
.split { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="page">
<header class="site-header">
<span class="brand">HTML NOTES</span>
<nav aria-label="页面导航">
<a href="#layers">四层</a>
<a href="#split">分工</a>
</nav>
</header>
<main>
<p class="eyebrow">LESSON / 02</p>
<h1>文档骨架</h1>
<p class="lead">
每个页面都从同一套骨架开始:doctype 告诉浏览器标准模式,html 包住全部,
head 放元数据,body 放用户能看到的内容。
</p>
<section id="layers">
<h2>四个部分</h2>
<ol>
<li><code><!doctype html></code>:声明标准模式。</li>
<li><code><html lang="zh-CN"></code>:文档根与语言。</li>
<li><code><head></code>:编码、视口、标题、描述。</li>
<li><code><body></code>:标题、段落、导航、页脚。</li>
</ol>
<pre><code><!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>页面标题</title>
</head>
<body>
<h1>页面内容</h1>
</body>
</html></code></pre>
</section>
<section id="split">
<h2>head 与 body 的分工</h2>
<div class="split">
<div class="box">
<h3>head</h3>
<ul>
<li>不直接显示</li>
<li>charset / viewport</li>
<li>title / description</li>
</ul>
</div>
<div class="box">
<h3>body</h3>
<ul>
<li>用户看到的内容</li>
<li>header / main / footer</li>
<li>标题、段落、链接</li>
</ul>
</div>
</div>
</section>
</main>
<footer>
<p>示例数据,仅用于教程演示。</p>
</footer>
</div>
</body>
</html>