Open
Description
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.
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
hasdisplay: 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 theinherit
keyword). - Alternatively, inheritance could be from
::contents
for all properties, and assignall: inherit
to::contents
in UA origin. - This pseudo-element does not affect selectors.