Search code examples
csssizeweb-component

Web Component - Sizing


When I create Web Components the default size is 0x0, despite containing elements.
For example here my element is 0x0:

Custom Element width,height = 0,0

But when I hover over the button contained within then you can see the button does have a width and height:

Hovever child element does have size

So my question is how can I make the custom element the same size as the child element?
Why does this happen?
I suspect it is due to the shador DOM and <slot>, but surly there must be a trick to give the custom element the correct height?

Many thanks


Solution

  • I created an example on StackBlitz... The fault was mine, the <slot> is inside an absolutely positioned <div> inside the shadow root... Silly me!