Why `container-type: size` CSS prop sets height to zero?

800 Views Asked by At

And how to bring height back, keeping container-type: size in place? Sample: https://jsfiddle.net/yakunins/cy3b68uk/

<div style="container-type: size;">Height of this div is zero.</div>
2

There are 2 best solutions below

3
Alohci On BEST ANSWER

Because it sets size containment. A size container cannot depend on the size of its contents, so it behaves as if its content size is 0.

You must set an explicit height for the size container.

1
Marc L. On

Container type doesn't have full support yet, as of 18th Nov 22.

Elements that use container size must have a defined size property, as the child elements will use a portion of this to calculate their own sizes.