如何使生成的内容可选? [英] How can I make generated content selectable?

查看:104
本文介绍了如何使生成的内容可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以让CSS使用生成的内容显示元素的ID,如下所示:

I can have CSS display the ID for an element by using generated content, like this:

<style>
h2:hover:after {
  color: grey;
  content: "#" attr(id);
  float: right;
  font-size: smaller;
  font-weight: normal;
}
</style>
<h2 id="my-id">My ID</h2>
<p>Pellentesque habitant morbi tristique senectus et netus et.</p>

如何使生成的内容(#my-id)可选,以便用户可以突出并复制它?

How can I make that generated content ("#my-id") selectable so that the user can highlight and copy it?

推荐答案

不能使伪元素可选,因为它不存在于DOM 。

You can't make a pseudo-element selectable, as it doesn't exist in the DOM.


5.10伪元素和伪类

5.10 Pseudo-elements and pseudo-classes

伪元素或伪类不会出现在文档源或文档中树。

Neither pseudo-elements nor pseudo-classes appear in the document source or document tree.

这篇关于如何使生成的内容可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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