Skip to content

[css-pseudo] Add a ::contents pseudo-element #2406

Open
@Loirooriol

Description

@Loirooriol

Some years ago I proposed a ::contents pseudo-element. I have been refining the details in https://github.com/Loirooriol/css-contents, and yesterday someone proposed the same idea, so I decided to file this issue.

To summarize, elements generate a ::before pseudo-elements at the beginning of their contents, and an ::after one at the end. This proposal wraps the contents inside a new ::contents pseudo-element.

image

In some way this is the opposite of display: contents: it allows you to insert a box between an element and its children, without needing to change the HTML in non-semantic ways.

You can see all the details and examples in https://github.com/Loirooriol/css-contents, but the behavior is:

  • ::contents has display: contents by default, via a rule in the UA origin. This can be overridden so that it does generate boxes.
  • ::contents can be styled with arbitrary properties.
  • ::contents has no effect in replaced elements.
  • ::contents inherits from its originating element.
  • Elements and text nodes inherit inheritable properties from the ::contents originated by the parent element. For non-inherited properties, inheritance is directly from the parent element (to avoid breaking the inherit keyword).
  • Alternatively, inheritance could be from ::contents for all properties, and assign all: inherit to ::contents in UA origin.
  • This pseudo-element does not affect selectors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions