「内容」继承节点值的属性
有没有办法将节点值继承到 content
属性中?
例如,如果
标签值设置为“随机标题”,我可以在 CSS 的 content
属性中获取该值吗?
我尝试过content:inherit;
,但它似乎不起作用。
我的理论的一个例子:
HTML:
<h2>Random title</h2>
CSS:
h2:after {
content: inherit; /* should be "Random title" */
}
提前致谢!
Is there a way to inherit node value into content
attribute?
Like, if <h2/>
tag value is set to "Random title", can I get this value inside content
attribute in CSS?
I've tried content: inherit;
, but it doesn't seem to work.
An example of my theory:
HTML:
<h2>Random title</h2>
CSS:
h2:after {
content: inherit; /* should be "Random title" */
}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有办法做到这一点。这不是
继承
的用途。你能得到的最接近的是:
..由于重复,这显然是可怕的。
No, there's no way to do that. That's not what
inherit
is for.The closest you can get is this:
..which is obviously horrible because of the duplication.
CSS3 有一种方法,
content:contents;
,但是 (a) 它似乎是用这样的方式设计的,没有用; (b) 可能尚未在任何地方实施。请参阅http://dev.w3.org/csswg/css3-content/#contents0< /a>@thirtydot 的答案至少目前是正确的。
CSS3 has a way,
content: contents;
but (a) it seems to be contrived in such a way as to not be useful; and (b) probably isn't implemented anywhere yet. See http://dev.w3.org/csswg/css3-content/#contents0@thirtydot's answer is correct for now, at least.