FAQ Page
你将构建什么
`faq.HTML` file 使用 page heading and four collapsible 问题/答案块 构建仅 使用 native details and summary 元素.
学习目标
- Use details/summary 元素 for native collapsible 小节
- 结构 repeated 内容使用 consistent 模式
- 编写 accessible markup 不使用 extra ARIA or JS
- 添加 minimal CSS 到制作 page feel polished
前置要求
- HTML document 结构
- Headings and paragraphs
步骤
- 1
设置 page and heading
创建
faq.HTML使用标准 skeleton and h1 "Frequently Asked Questions". 添加短 intro paragraph 所以 visitors know 什么这个 page 是 for.代码<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>FAQ</title> </head> <body> <h1>Frequently Asked Questions</h1> <p>Everything you need to know to get started.</p> </body> </html>预期结果
page 使用 title and intro paragraph.
- 2
添加首先问题
details 元素创建 collapsible 块. summary 是总是-可见 label; 一切 else 内部 details 是隐藏答案. 添加 one 问题到 see 模式.
代码<details> <summary>What is this project about?</summary> <p>It is a beginner-friendly FAQ built with native HTML, no JavaScript required.</p> </details>预期结果
行使用 triangle marker and 问题文本; 点击它 reveals 答案.
提示
添加打开 attribute 到 details 如果你 想要它 expanded 通过默认.
- 3
添加 three 更多问题
Repeat details/summary 模式 for three 更多问题. 复制-粘贴是 fine 这里 — repetition 是点, and 你将 see 如何 consistent 结构 scales.
代码<details> <summary>Do I need to know CSS?</summary> <p>No, but a little CSS makes it look nicer. This project includes a small stylesheet.</p> </details> <details> <summary>Can I add more questions later?</summary> <p>Yes — just copy one details block and change the text.</p> </details> <details> <summary>Is this accessible?</summary> <p>Yes. details and summary are native elements with keyboard and screen-reader support built in.</p> </details>预期结果
Four collapsible 行 appear, 每个 independently expandable.
- 4
添加 minimal 样式
添加样式块 in head 到设置字体, give 请求体一些 padding, and 添加底部边框到 每个 summary 所以行 look 如列表. 小 CSS goes 长方式.
代码body { font-family: system-ui, sans-serif; max-width: 40rem; margin: 2rem auto; padding: 0 1rem; } summary { cursor: pointer; padding: 0.75rem 0; border-bottom: 1px solid #e2e8f0; } summary:hover { color: #2563eb; }预期结果
page 是 centered, readable, and 每个行 有 divider 行使用 hover 颜色.
- 5
添加响应式样式
使用媒体查询为移动端调整布局:在小屏幕上将多列改为单列、缩小字号、调整间距。移动优先意味着小屏幕体验同样重要。
代码@media (max-width: 640px) { .container { flex-direction: column; padding: 1rem; } h1 { font-size: 1.5rem; } .card { width: 100%; margin-bottom: 1rem; } }预期结果
在 640px 以下视口,布局变为单列,字号和间距缩小,内容不溢出。
自己动手试试
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FAQ</title>
</head>
<body>
<h1>Frequently Asked Questions</h1>
<!-- TODO: add 4 details/summary blocks -->
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FAQ</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 40rem; margin: 2rem auto; padding: 0 1rem; }
summary { cursor: pointer; padding: 0.75rem 0; border-bottom: 1px solid #e2e8f0; }
summary:hover { color: #2563eb; }
</style>
</head>
<body>
<h1>Frequently Asked Questions</h1>
<p>Everything you need to know to get started.</p>
<details>
<summary>What is this project about?</summary>
<p>It is a beginner-friendly FAQ built with native HTML, no JavaScript required.</p>
</details>
<details>
<summary>Do I need to know CSS?</summary>
<p>No, but a little CSS makes it look nicer. This project includes a small stylesheet.</p>
</details>
<details>
<summary>Can I add more questions later?</summary>
<p>Yes — just copy one details block and change the text.</p>
</details>
<details>
<summary>Is this accessible?</summary>
<p>Yes. details and summary are native elements with keyboard and screen-reader support built in.</p>
</details>
</body>
</html>你学到了什么
你 used native details/summary 元素到 构建 accessible, collapsible FAQ 使用零 JavaScript — great 示例的 letting platform 做工作.
相关资源
相关课程
相关练习
- HTML 标签 MCQ
测验 on 选择正确元素 for 正确作业.
- Accessibility MCQ
基础的 accessible markup — 为什么 native 元素 win.
相关工具
- HTML/CSS/JS Minifier
Minify 你的 FAQ page markup for production.
相关速查表
- HTML Cheatsheet
引用 for details, summary, and 结构标签 used.
- CSS Cheatsheet
属性 used in minimal 样式步骤.
相关参考文档
- HTML 元素引用
引用 for details, summary, and sectioning 元素.
相关错误
- JavaScript 不加载
Script 不执行.
- CSS Selector 不 Matching
Selectors 不 applying 样式.
相关术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
相关错误
用大白话解释常见错误——什么意思、为什么发生、如何修复。
- JavaScript 不加载
Script 不执行.
- CSS Selector 不 Matching
Selectors 不 applying 样式.