html - 使用 CSS 为段落添加双引号

标签 html css

假设我有这一段:

<p class="myclass">This is my paragraph</p>

给这段添加双引号的CSS代码是什么? (所以它会呈现“这是我的段落”)

.myclass {}

最佳答案

实际上,接受的答案是错误的,或者至少是次优的。应该是:

q { quotes: '\201c' '\201d'; }
q:before { content: open-quote; }
q:after  { content: close-quote; }

此处的 \201c 是左弯双引号的 Unicode。没有理由不能在 q 的规则中直接写双引号:

q { quotes: '“' '”'}

open-quoteclose-quotecontent 属性的特殊值,它们指的是作为 quotes 属性。

现在你可以说:

<p><q>This is my paragraph</q></p>

或其一些变体;如果您愿意,您当然可以直接在 p 上添加 beforeafter 规则:

body { quotes: '\201c' '\201d'; }
p:before { content: open-quote; }
p:after  { content: close-quote; }

这允许您使用 quotes 属性分解出用于引号的特定字符,而无需更改所有 beforeafter 规则。例如,您可以执行诸如

:lang(de) { quotes: "»" "«"; }

如果 lang 属性已在任何祖先上设置为 de,则获取德语风格的引号。

quotes 属性实际上允许您指定额外的引号集,用于嵌套引号。有关详细信息,请参阅文档。

body { quotes: '\201c' '\201d'; }
q:before { content: open-quote; }
q:after  { content: close-quote; }

:lang(de) { quotes: "»" "«"; }
<p>Quoth the raven, <q>Never more.</q></p>

<p lang="de">Sprach der Rabe: <q>Nie du Tor.</q></p>

引用资料:

关于html - 使用 CSS 为段落添加双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8040217/

相关文章:

带变量和乘法的 CSS Calc

asp.net - 不透明度问题 - 还设置图像

html - 使用表格而不是 div 会给最终用户带来什么真正的问题?

html - 按钮不会对 CSS 中的填充或边距使用react

javascript - 更改 style.top 时图像不移动

css - 如何向 <pre> 内的 <li> 内的多个 <span> 添加填充

user-agent - 是什么导致 "user agent stylesheet"使用 "border-box"而不是 "content-box"来调整盒子大小?

html - 在连续流上解码音频数据失败并出现空错误

php - 谷歌的 Robots.txt 错误

html - 基础媒体查询范围错误