CSS - 将文本添加到样式表中的样式

2024-03-24

我还没有找到任何文档,所以我认为这是不可行的。 但值得一问。

我可以在样式表内指定样式内的实际文本吗?

我有几个地方在相同的 div 位置使用相同的文本。我没有使用 javascript 或在 div 中重新输入相同的文本,而是在考虑样式是否可以在其中插入实际的“文本”。

.someclass {
  text:"for example";  /* this is how I'd imagine it, IF it were possible */
  color:#000;
}

我可能会推这个。


您正在寻找content http://www.w3.org/TR/CSS2/generate.html#content财产。

不幸的是,它只能与伪元素一起使用。

此属性与 :before 和 :after 伪元素一起使用以在文档中生成内容。

所以你可以做类似的事情...

.someclass:before {
   content: "This text will be added at the beginning of the element"
}
.someclass:after {
   content: "This text will be added at the end of the element"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CSS - 将文本添加到样式表中的样式 的相关文章