字体
用于控制 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="你好世界" class="before:content-[attr(before)] ..."> <!-- ... --></p>
由于空格在 HTML 中表示类的结束,请将任意值中的空格替换为下划线:
<p class="before:content-['你好_世界'] ..."></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-['手机'] md:before:content-['桌面'] ..."></p>
Learn more about using variants in the variants documentation.