[csswg-drafts] [css-contain] Should `content-visibility` apply to elements when size containment has no effect? (#7658)

Loirooriol has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-contain] Should `content-visibility` apply to elements when size containment has no effect? ==
https://drafts.csswg.org/css-contain/#content-visibility

> Applies to: elements for which layout containment can apply

That is, if

 - the element generates a [principal box](https://drafts.csswg.org/css-display-3/#principal-box), and
 - its [principal box](https://drafts.csswg.org/css-display-3/#principal-box) is not an [internal table box](https://drafts.csswg.org/css-display-3/#internal-table-box) or is a [table-cell](https://drafts.csswg.org/css-display-3/#valdef-display-table-cell), and
 - its [principal box](https://drafts.csswg.org/css-display-3/#principal-box) is not an [internal ruby box](https://drafts.csswg.org/css-display-3/#internal-ruby-box) nor a [non-atomic](https://drafts.csswg.org/css-display-3/#atomic-inline) [inline-level](https://drafts.csswg.org/css-display-3/#inline-level) box

Note that `content-visibility` can trigger:
 - Layout containment, which is guaranteed to work by "applies to".
 - Paint containment, which is guaranteed to work since it has the same requirements as layout containment.
 - Style containment, which is guaranteed to work since it applies to all elements.
 - Size containment

Size containment has similar requirements:

 - the element generates a [principal box](https://drafts.csswg.org/css-display-3/#principal-box), and
 - its [inner display type](https://drafts.csswg.org/css-display-3/#inner-display-type) is not [table](https://drafts.csswg.org/css-display-3/#valdef-display-table), and
 - its [principal box](https://drafts.csswg.org/css-display-3/#principal-box) is not an [internal table box](https://drafts.csswg.org/css-display-3/#internal-table-box), and
 - its [principal box](https://drafts.csswg.org/css-display-3/#principal-box) is not an [internal ruby box](https://drafts.csswg.org/css-display-3/#internal-ruby-box) nor a [non-atomic](https://drafts.csswg.org/css-display-3/#atomic-inline) [inline-level](https://drafts.csswg.org/css-display-3/#inline-level) box

The difference is that layout containment has effect in a `table` and `table-cell` boxes, so `content-visibility` applies, but size containment has no effect.

Consider [this testcase](https://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Cstyle%3Etable%20%7B%20border%3A%20solid%20%7D%20td%20%7B%20border%3A%20solid%20blue%20%7D%3C%2Fstyle%3E%0A%3Ctable%3E%3Ctd%20style%3D%22content-visibility%3A%20hidden%22%3ELorem%3C%2Ftd%3E%3C%2Ftable%3E%0A%3Ctable%20style%3D%22content-visibility%3A%20hidden%22%3E%3Ctd%3EIpsum%3C%2Ftd%3E%3C%2Ftable%3E):

```html
<!DOCTYPE html>
<style>table { border: solid } td { border: solid blue }</style>
<table><td style="content-visibility: hidden">Lorem</td></table>
<table style="content-visibility: hidden"><td>Ipsum</td></table>
```

"Lorem" is not painted in either Firefox nor Chromium. But in Firefox, due to the lack of size containment, the size of the cell takes the contents into account! Seems to follow the spec, but does this make sense? Chromium ignores the requirements and force-applies size containment.

"Ipsum" is similarly not painted in Firefox, while the table takes the size of the contents. Chromium just ignores `content-visibility: hidden` in this case.

So maybe say that `content-visibility` doesn't apply when size containment has no effect? And BTW I still think it would make more sense if size containment worked in table cells, see #1791.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7658 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 29 August 2022 19:54:16 UTC