如何用 CSS 设置 blockquote 引用块的样式
创建时间 2026-11-22
最后修改 2026-11-22
用 HTML <blockquote>标记独立的引用段落,再用 CSS 设置边框、背景和间距。示例用 <figure> 将引文与来源分组,在行起始侧添加强调线,还可以按需显示装饰引号。
标记引文及来源
独立引用使用 <blockquote>,句子中的简短引用可用 <q>。要突出自己写的文字,可以给相应的段落或容器添加 CSS 类。
blockquote 的 cite 属性可以记录来源网址,但它本身不会显示可点击链接。请在 <figcaption> 中添加链接,用 <cite> 标记作品或文档标题,必要时把作者姓名写在标题旁边。
HTML 标准中的 blockquote 规则 · HTML 标准中的 cite 元素
在浏览器中运行带边框的完整示例
将完整代码保存为 UTF-8 编码的 blockquote-demo.html,然后在浏览器中打开。无需安装任何库。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>引用块样式示例</title>
<style>
body {
max-width: 42rem;
margin: 2rem auto;
padding-inline: 1rem;
font: 1rem/1.65 system-ui, sans-serif;
}
.quote {
margin-block: 1.5rem;
margin-inline: 0;
padding: 1rem 1.25rem;
border-inline-start: .35rem solid #2563eb;
background: #eff6ff;
color: #172554;
}
.quote blockquote { margin: 0; }
.quote blockquote p { margin: 0; overflow-wrap: anywhere; }
.quote figcaption { margin-block-start: .75rem; }
.quote__mark { display: none; }
.quote--decorative .quote__mark {
display: block;
color: #2563eb;
font: 3rem/1 Georgia, serif;
}
</style>
</head>
<body>
<figure class="quote">
<span class="quote__mark" aria-hidden="true">“</span>
<blockquote cite="https://html.spec.whatwg.org/multipage/grouping-content.html#the-blockquote-element">
<p lang="en" dir="ltr">The blockquote element represents a section that is quoted from another source.</p>
</blockquote>
<figcaption>
<a href="https://html.spec.whatwg.org/multipage/grouping-content.html#the-blockquote-element" lang="en"><cite>HTML Standard</cite></a>
</figcaption>
</figure>
</body>
</html>
引文显示在浅蓝色卡片中,行起始侧有一条蓝色边框,下方有来源链接。margin-inline: 0 去掉卡片两侧的外边距,padding 留出边框与文字之间的空间。针对 blockquote 的规则去掉浏览器默认缩进。
添加装饰引号并测试文字方向
装饰引号位于引文外部的 <span> 中。aria-hidden="true" 只从无障碍树中隐藏该装饰符号。引文和来源链接仍然可访问。
- 给
<figure>添加quote--decorative类,引文上方会出现大引号。移除该类即可隐藏。 - 暂时给
<figure>加上dir="rtl"。在横排文字中,border-inline-start设定的强调线会移到右侧。删除属性即可恢复。
检查移动端和主题中的效果
将样式限定在 .quote 内,以免影响主题中的其他引用。如果边框没有出现或缩进过大,请分别检查 figure 的计算边框和内部 blockquote 的外边距。
缩小窗口,确认文字能在卡片内换行,来源链接仍可以点击。overflow-wrap: anywhere 允许特别长的单词断行。调整颜色时请保持文字与实际背景之间的对比度。




