'content' attribute to inherit node value

后端 未结 2 1393
情话喂你
情话喂你 2020-12-07 00:42

Is there a way to inherit node value into content attribute?

Like, if

tag value is set to \"Random title\", can I get this valu

相关标签:
2条回答
  • 2020-12-07 01:31

    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.

    0 讨论(0)
  • 2020-12-07 01:33

    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.

    0 讨论(0)
提交回复
热议问题