大网数据广告活动
Web 标准与前端开发

CSSPseudoElement

· 52CE 我爱测

The **`CSSPseudoElement`** interface represents a pseudo-element.

The CSSPseudoElement interface represents a pseudo-element.

Instances of this interface may be obtained by calling Element.pseudo() or CSSPseudoElement.pseudo().

Instance properties

  • CSSPseudoElement.element
    • : Returns the ultimate originating Element of the pseudo-element.
  • CSSPseudoElement.parent
    • : Returns the immediate originating element of the pseudo-element.
  • CSSPseudoElement.type
    • : Returns the pseudo-element selector as a string.

Instance methods

  • CSSPseudoElement.pseudo()

Description

The CSSPseudoElement interface represents a pseudo-element. You can retrieve a representation of a pseudo-element attached to a DOM element using the Element.pseudo() method, or a representation of a nested pseudo-element (for example, the ::marker in ::before::marker) using the CSSPseudoElement.pseudo() method.

The CSSPseudoElement.type property returns a string representing the type of the pseudo-element. Supported types are:

  • ::after
  • ::before
  • ::marker

The CSSPseudoElement.element and CSSPseudoElement.parent properties sound similar, but they have a difference in functionality:

  • The element property always returns an Element: A reference to the ultimate originating element of the pseudo-element or nested pseudo-element.
  • The parent property returns a reference to the pseudo-element's immediate originating element: This can be either an Element, or a CSSPseudoElement in the case of a nested pseudo-element.

Examples

Basic example using Element.pseudo

Using pseudo-elements, most modern browsers will automatically add quotation marks around text inside a q element. (A style rule may be needed to add quotation marks in older browsers.) The example below demonstrates the basic properties of the CSSPseudoElement object representing the opening quotation mark.

const element = document.querySelector("q");
const cssPseudoElement = element.pseudo("::before");
console.log(cssPseudoElement.element); // Outputs [object HTMLQuoteElement]
console.log(cssPseudoElement.type); // Outputs '::before'

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。