Making Generated Content Selectable
One way to display hidden element identifiers is by using generated content within CSS. For instance:
h2:hover:after { color: grey; content: "#" attr(id); float: right; font-size: smaller; font-weight: normal; }
However, there's a limit to this approach.
Question: Is there a way to enable users to select and copy the ID ("#my-id") created by generated content?
Answer: Unfortunately, no.
This is because pseudo-elements are not part of the DOM (Document Object Model). As per section 5.10 of CSS2.1, neither pseudo-elements nor pseudo-classes are found in the document source or document tree. Therefore, making generated content selectable is not possible.
以上是使用者是否可以選擇並複製由 CSS 中產生的內容所建立的 ID?的詳細內容。更多資訊請關注PHP中文網其他相關文章!