是否可以通过CSS 3使用文本内容设置元素中的文本的颜色? [英] Is it possible via CSS 3 to set the color of text in an element using the text content?
问题描述
好吧,这是一个更多的问题,有很多的解决方案不是CSS,但我正在寻找这样做更多从理论的角度。我有一个应用程序,但它不值得以任何其他方式编码。
Okay, so this is more of a question that has lots of solutions that are not CSS, but I'm looking for doing this more from a theoretical perspective. I have an application for it, but its not worth coding it out in any other way.
如何使用元素的文本对元素的文本着色?我有一个元素,所有在它自己的,它将包含一个颜色的十六进制值,我想要的文本是那种颜色,但我想做它只使用CSS(可能只能使用CSS 3)。
How do you color the text of an element using the text of the element? I have an element, all on it's own, which will contain a hex value for a color, and I want the text to be that color, but I want to do it only using CSS (likely only can be done using CSS 3).
<div class="color_contents">#0000FF</div>
所以,我试着使用 attr c $ c>没有成功,但我不确定我使用正确的内容(我试过
文本
, textContent
和
innerText
无效)。
So, I've tried to use the attr()
with no success, but I'm not sure I'm using the right contents (I've tried text
, textContent
, and innerText
to no avail). Doesn't need to be cross-browser, but just a way to accomplish it.
推荐答案
目前,没有办法使用CSS访问元素的文本内容,甚至没有今天可用的CSS3模块。
Currently, there is no way to use CSS to access an element's text content, not even with the CSS3 modules available today.
关于:
所以,我试图使用
attr()
没有成功,但我不确定我使用正确的内容(我试过text
,textContent
和innerText
无效)。不需要是跨浏览器,而只是一种实现方式。
So, I've tried to use the
attr()
with no success, but I'm not sure I'm using the right contents (I've triedtext
,textContent
, andinnerText
to no avail). Doesn't need to be cross-browser, but just a way to accomplish it.
attr
仅查看元素属性( foo =bar
)。由于文本内容不是HTML元素的属性(尽管是相应的DOM对象的成员),您不能使用该函数查询它。
attr()
only looks at element attributes (foo="bar"
). Since text content isn't an attribute of an HTML element (despite being a member of the corresponding DOM object), you can't query for it using that function.
没有类似的函数来访问元素的文本内容。
There isn't a similar function for accessing an element's text content.
这篇关于是否可以通过CSS 3使用文本内容设置元素中的文本的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!