排版
用于控制 'before' 和 'after' 伪元素内容的工具。
Class | Styles |
---|---|
content-[<value>] | content: <value>; |
content-(<custom-property>) | content: var(<custom-property>); |
content-none | content: none; |
使用 content-[<value>]
语法,以及 before
和 after
变体,来设置 ::before
和 ::after
伪元素的内容:
<p>更高的分辨率不仅意味着更好的图像质量。使用一个Retina 6K 显示器, <a class="text-blue-600 after:content-['_↗']" href="...">Pro Display XDR</a> 给你提供比 5K 显示器多出近 40% 的屏幕空间。</p>
使用 content-[attr(<name>)]
语法来引用存储在属性中的值,使用 attr()
CSS 函数:
<p before="Hello World" class="before:content-[attr(before)] ..."> <!-- ... --></p>
由于空格在 HTML 中表示一个类的结束,请将任意值中的空格替换为下划线:
<p class="before:content-['Hello_World'] ..."></p>
如果需要包含一个实际的下划线,则可以通过使用反斜杠进行转义:
<p class="before:content-['Hello\_World']"></p>
使用 content-(<custom-property>)
语法,通过 CSS 变量控制 ::before
和 ::after
伪元素的内容:
<p class="content-(--my-content)"></p>
这只是为 content-[var(<custom-property>)]
添加 var()
函数的快捷方式。
Prefix a content
utility with a breakpoint variant like md:
to only apply the utility at medium screen sizes and above:
<p class="before:content-['Mobile'] md:before:content-['Desktop'] ..."></p>
Learn more about using variants in the variants documentation.