'content'属性继承节点值 [英] 'content' attribute to inherit node value

查看:149
本文介绍了'content'属性继承节点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有方法可以将节点值继承到 content 属性?



c>< h2 /> 标记值设置为随机标题,我可以在CSS中 content / p>

我尝试过 content:inherit; ,但似乎无效。



我的理论范例:



HTML:

 < h2>随机标题< / h2> 

CSS:

  h2:after {
content:inherit; / *应为随机标题* /
}

p>

解决方案

不,没有办法。这不是 继承

 

< h2 data-title =Random title>随机标题< / h2>

h2:after {
content:attr(data-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!

解决方案

No, there's no way to do that. That's not what inherit is for.

The closest you can get is this:

<h2 data-title="Random title">Random title</h2>

h2:after {
    content: attr(data-title);
}

..which is obviously horrible because of the duplication.

这篇关于'content'属性继承节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆