← CSS ::placeholder 伪元素 CSS resize 属性 →

CSS quotes 属性

原创 2025-09-09 CSS 已有人查阅

CSS quotes 属性详解与应用指南

概述与定义

CSS quotes 属性用于定义文档中引用的显示方式,控制引号标记的样式和层级。该属性与 content 属性的 open-quote 和 close-quote 值配合使用,可以精确控制不同层级引用的显示样式。

通过 quotes 属性,开发者可以自定义各种语言的引号样式,实现多语言支持和排版美化效果。

基本语法与属性值

selector {
  quotes: none | [string string]+ | initial | inherit;
}

属性值说明

  • none:默认值,open-quote 和 close-quote 值不生成任何引号标记

  • string:定义一对或多对引号标记,第一对用于最外层引用,后续对用于嵌套引用

  • initial:将属性重置为默认值

  • inherit:继承父元素的对应属性值

常用引号字符编码表

描述 字符 Unicode编码
双引号 " \0022
单引号 ' \0027
双低9引号 \201E
左双角引号 « \00AB
右双角引号 » \00BB
左单角引号 \2039
右单角引号 \203A
左单引号 \2018
右单引号 \2019
左双引号 " \201C
右双引号 " \201D

基础应用示例

1. 基本引号样式设置

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS quotes属性基础应用 - 代码号编程学习</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1.6;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f9f9f9;
        }
        
        h1, h2 {
            color: #2c3e50;
            text-align: center;
        }
        
        .example-container {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .quote-style {
            quotes: "「" "」";
            font-size: 18px;
            margin: 15px 0;
            padding: 10px;
            background-color: #f0f7ff;
            border-left: 4px solid #3498db;
        }
        
        .quote-style:before {
            content: open-quote;
            color: #e74c3c;
            font-weight: bold;
        }
        
        .quote-style:after {
            content: close-quote;
            color: #e74c3c;
            font-weight: bold;
        }
        
        .double-angle {
            quotes: "«" "»";
        }
        
        .single-angle {
            quotes: "‹" "›";
        }
        
        .english-style {
            quotes: "\201C" "\201D";
        }
        
        .code-sample {
            background-color: #2c3e50;
            color: #ecf0f1;
            padding: 15px;
            border-radius: 5px;
            font-family: monospace;
            margin-top: 15px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <h1>CSS quotes 属性应用示例</h1>
    
    <div class="example-container">
        <h2>中文引号样式</h2>
        <p class="quote-style">欢迎访问代码号编程学习平台,这里提供丰富的前端开发教程。</p>
        
        <div class="code-sample">
            .quote-style {<br>
            &nbsp;&nbsp;quotes: "「" "」";<br>
            }<br>
            .quote-style:before {<br>
            &nbsp;&nbsp;content: open-quote;<br>
            }<br>
            .quote-style:after {<br>
            &nbsp;&nbsp;content: close-quote;<br>
            }
        </div>
    </div>
    
    <div class="example-container">
        <h2>法语风格引号</h2>
        <p class="quote-style double-angle">代码号提供HTML、CSS、JavaScript等多种编程语言教程。</p>
        
        <div class="code-sample">
            .double-angle {<br>
            &nbsp;&nbsp;quotes: "«" "»";<br>
            }
        </div>
    </div>
    
    <div class="example-container">
        <h2>英语风格引号</h2>
        <p class="quote-style english-style">学习编程较好的方法是理论与实践相结合。</p>
        
        <div class="code-sample">
            .english-style {<br>
            &nbsp;&nbsp;quotes: "\201C" "\201D";<br>
            }
        </div>
    </div>
</body>
</html>

2. 多层级嵌套引用

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多层级嵌套引用 - 代码号教程</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        
        .nested-quotes {
            quotes: "「" "」" "『" "』" "【" "】";
            font-size: 16px;
            margin: 20px 0;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        q {
            quotes: inherit;
        }
        
        q:before {
            content: open-quote;
            color: #e74c3c;
            font-weight: bold;
        }
        
        q:after {
            content: close-quote;
            color: #e74c3c;
            font-weight: bold;
        }
        
        .example-desc {
            color: #7f8c8d;
            font-style: italic;
            margin-top: 10px;
        }
        
        .code-sample {
            background-color: #34495e;
            color: #ecf0f1;
            padding: 15px;
            border-radius: 5px;
            font-family: 'Courier New', monospace;
            margin-top: 15px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <h1>多层级嵌套引用示例</h1>
    
    <div class="nested-quotes">
        <q>代码号编程学习平台<q>提供了<q>丰富的前端开发教程</q>和实战项目</q>,适合各层次开发者学习</q>
        
        <p class="example-desc">此示例展示了三层嵌套引用,每层使用不同的引号样式。</p>
    </div>
    
    <div class="code-sample">
        .nested-quotes {<br>
        &nbsp;&nbsp;quotes: "「" "」" "『" "』" "【" "】";<br>
        }<br><br>
        q {<br>
        &nbsp;&nbsp;quotes: inherit;<br>
        }<br><br>
        q:before {<br>
        &nbsp;&nbsp;content: open-quote;<br>
        &nbsp;&nbsp;color: #e74c3c;<br>
        &nbsp;&nbsp;font-weight: bold;<br>
        }<br><br>
        q:after {<br>
        &nbsp;&nbsp;content: close-quote;<br>
        &nbsp;&nbsp;color: #e74c3c;<br>
        &nbsp;&nbsp;font-weight: bold;<br>
        }
    </div>
    
    <div class="nested-quotes" style="quotes: '«' '»' '‹' '›' '\201C' '\201D';">
        <q>CSS quotes属性<q>可以定义<q>多级引号样式</q>实现复杂排版</q>,提升文档可读性</q>
        
        <p class="example-desc">此示例使用西方风格的引号进行多层级嵌套。</p>
    </div>
</body>
</html>

3. 多语言引号支持

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多语言引号支持 - 代码号学习示例</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f0f3f5;
        }
        
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
        }
        
        .language-example {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        :lang(zh) q {
            quotes: "「" "」";
        }
        
        :lang(en) q {
            quotes: "\201C" "\201D";
        }
        
        :lang(fr) q {
            quotes: "«" "»";
        }
        
        :lang(de) q {
            quotes: "\201E" "\201C";
        }
        
        q:before {
            content: open-quote;
            color: #3498db;
            font-weight: bold;
        }
        
        q:after {
            content: close-quote;
            color: #3498db;
            font-weight: bold;
        }
        
        .language-label {
            display: inline-block;
            background-color: #e74c3c;
            color: white;
            padding: 3px 8px;
            border-radius: 3px;
            font-size: 14px;
            margin-right: 10px;
        }
        
        .code-sample {
            background-color: #2c3e50;
            color: #ecf0f1;
            padding: 15px;
            border-radius: 5px;
            font-family: monospace;
            margin-top: 15px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <h1>多语言引号支持示例</h1>
    
    <div class="language-example">
        <p><span class="language-label">中文</span> 
            <q lang="zh">代码号编程学习平台提供全面的前端开发教程</q>
        </p>
        
        <p><span class="language-label">英文</span> 
            <q lang="en">Learn programming with practical examples and projects</q>
        </p>
        
        <p><span class="language-label">法文</span> 
            <q lang="fr">Apprenez la programmation avec des tutoriels détaillés</q>
        </p>
        
        <p><span class="language-label">德文</span> 
            <q lang="de">Programmieren lernen mit praktischen Beispielen</q>
        </p>
    </div>
    
    <div class="code-sample">
        :lang(zh) q {<br>
        &nbsp;&nbsp;quotes: "「" "」";<br>
        }<br><br>
        :lang(en) q {<br>
        &nbsp;&nbsp;quotes: "\201C" "\201D";<br>
        }<br><br>
        :lang(fr) q {<br>
        &nbsp;&nbsp;quotes: "«" "»";<br>
        }<br><br>
        :lang(de) q {<br>
        &nbsp;&nbsp;quotes: "\201E" "\201C";<br>
        }
    </div>
    
    <div class="language-example">
        <h2>实际应用场景</h2>
        <p>在多语言网站中,使用CSS quotes属性可确保每种语言都使用符合其文化习惯的引号样式,提升用户体验和内容专业性。</p>
        
        <p>访问<a href="https://www.ebingou.cn/jiaocheng/" style="color: #2980b9; text-decoration: none;">代码号教程页面</a>了解更多CSS技巧和应用实例。</p>
    </div>
</body>
</html>

4. 自定义引号样式与效果

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义引号样式 - 代码号编程示例</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f8f9fa;
        }
        
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
        }
        
        .custom-quotes {
            background-color: white;
            border-radius: 8px;
            padding: 25px;
            margin: 20px 0;
            box-shadow: 0 3px 10px rgba(0,0,0,0.1);
        }
        
        .style1 {
            quotes: "“" "”";
        }
        
        .style1 q:before,
        .style1 q:after {
            color: #e74c3c;
            font-size: 1.5em;
            font-weight: bold;
        }
        
        .style2 {
            quotes: "【" "】";
        }
        
        .style2 q:before,
        .style2 q:after {
            color: #3498db;
            background-color: #eaf2f8;
            padding: 2px 5px;
            border-radius: 3px;
        }
        
        .style3 {
            quotes: "«" "»";
        }
        
        .style3 q:before,
        .style3 q:after {
            color: #9b59b6;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
        }
        
        .style4 {
            quotes: "〈" "〉";
        }
        
        .style4 q:before,
        .style4 q:after {
            color: #2ecc71;
            font-family: 'Georgia', serif;
        }
        
        q {
            quotes: inherit;
            font-style: italic;
            background-color: #f9f9f9;
            padding: 5px 10px;
            border-radius: 4px;
            display: inline-block;
        }
        
        .style-label {
            display: block;
            font-weight: bold;
            color: #7f8c8d;
            margin-bottom: 10px;
            border-bottom: 1px dashed #ddd;
            padding-bottom: 5px;
        }
        
        .code-sample {
            background-color: #34495e;
            color: #ecf0f1;
            padding: 15px;
            border-radius: 5px;
            font-family: 'Courier New', monospace;
            margin-top: 15px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <h1>自定义引号样式示例</h1>
    
    <div class="custom-quotes">
        <span class="style-label">样式1:红色强调引号</span>
        <p><q class="style1">代码号提供HTML、CSS、JavaScript等前端技术教程</q></p>
        
        <span class="style-label">样式2:背景高亮引号</span>
        <p><q class="style2">通过实战项目学习编程是有效的方法</q></p>
        
        <span class="style-label">样式3:紫色阴影引号</span>
        <p><q class="style3">响应式设计是现代网页开发的基本要求</q></p>
        
        <span class="style-label">样式4:绿色衬线引号</span>
        <p><q class="style4">CSS quotes属性可以大幅提升排版专业性</q></p>
    </div>
    
    <div class="code-sample">
        /* 样式1 */<br>
        .style1 {<br>
        &nbsp;&nbsp;quotes: "“" "”";<br>
        }<br>
        .style1 q:before,<br>
        .style1 q:after {<br>
        &nbsp;&nbsp;color: #e74c3c;<br>
        &nbsp;&nbsp;font-size: 1.5em;<br>
        &nbsp;&nbsp;font-weight: bold;<br>
        }<br><br>
        /* 样式2 */<br>
        .style2 {<br>
        &nbsp;&nbsp;quotes: "【" "】";<br>
        }<br>
        .style2 q:before,<br>
        .style2 q:after {<br>
        &nbsp;&nbsp;color: #3498db;<br>
        &nbsp;&nbsp;background-color: #eaf2f8;<br>
        &nbsp;&nbsp;padding: 2px 5px;<br>
        &nbsp;&nbsp;border-radius: 3px;<br>
        }
    </div>
    
    <div class="custom-quotes">
        <h2>应用建议</h2>
        <p>通过自定义引号样式,可以使引用内容在视觉上更加突出,增强页面的设计感和专业性。在实际项目中,可以根据网站整体设计风格选择合适的引号样式。</p>
        
        <p>更多CSS技巧和前端开发知识,请访问<a href="https://www.ebingou.cn/biancheng/" style="color: #2980b9; text-decoration: none;">代码号编程学习平台</a>。</p>
    </div>
</body>
</html>

本节课程知识要点

  1. 基本功能:CSS quotes属性用于定义引用标记的显示样式,与content属性的open-quote和close-quote值配合使用

  2. 多级嵌套:支持定义多对引号标记,分别用于不同层级的嵌套引用

  3. 多语言支持:通过与lang属性和:lang伪类配合,可以实现多语言环境下的引号适配

  4. 自定义样式:可以通过CSS进一步美化引号标记的显示效果,包括颜色、大小、背景等

  5. 实用价值:合理使用quotes属性可以提升文档的专业性和可读性,特别是在多语言网站中

实际应用场景

  1. 多语言网站:为不同语言内容提供符合文化习惯的引号样式

  2. 学术出版物:确保学术文献中引用的准确性和格式规范性

  3. 新闻媒体网站:统一站点内引用内容的显示样式,增强品牌一致性

  4. 技术文档:清晰区分引用内容与普通文本,提高文档可读性

  5. 个性化设计:通过自定义引号样式增强页面的视觉吸引力

← CSS ::placeholder 伪元素 CSS resize 属性 →
分享笔记 (共有 篇笔记)
验证码:
微信公众号