首頁 >web前端 >css教學 >使用者是否可以選擇並複製由 CSS 中產生的內容所建立的 ID?

使用者是否可以選擇並複製由 CSS 中產生的內容所建立的 ID?

Susan Sarandon
Susan Sarandon原創
2024-11-15 10:17:02389瀏覽

Can Users Select and Copy IDs Created by Generated Content in CSS?

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中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn