Re: [csswg-drafts] [css-pseudo] Add a ::contents pseudo-element (#2406)

> I guess what you are proposing is that children elements in the DOM would remain being children in the element tree, they would just generate boxes inside ::contents.

That's my working mental image, yes. I've had another read through your full proposal, I think it's exactly the box model you proposed, just without the impact on inheritance. So I'm not really clear on what you mean by _where it would fit in the element tree_ - you mean for styling? As a pseudo-element it would inherit from it's owning element, exactly as for ::before. I suspect I've misunderstood the question!

Here's another way to phrase what I'm suggesting.

> The ::contents pseudo-element is auto-generated to surround the `contents` value of the `content` property. If `contents` is not used in the `content` property of the element or its ::before/::after pseudo-elements, the ::contents pseudo-element is not generated (which is the case for replaced content). The `content` property does not apply to the ::contents pseudo-element.

The element's default value of `content: normal` computes to `content: contents`, which means by default the box would be generated between the ::before and ::after pseudo-elements. And, as the ::contents pseudo-element defaults to `display: none`, the box is not generated by default, and we have the existing rendering model.

I've looked through the examples from your proposal and I think this will work for all of them. If there are cases where you think it's less useful, lets take a look and see if we can figure them out.  But I am struggling to imagine a case where you'd want the element's children to inherit styling from the ::contents pseudo-element.

The best example I could come up with that you haven't illustrated already was automatically generating table cells:

```css
td {
    display: contents;
}
td::before {
    content: attr(header);
    display: table-cell;
}
td::content {
     display: table-cell;
}

<td header="foo">bar</td>
```
to give the box model
```
<td::before>foo</td><td::content>bar</td::content>
```


-- 
GitHub Notification of comment by faceless2
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2406#issuecomment-581061668 using your GitHub account

Received on Saturday, 1 February 2020 19:27:33 UTC