Search code examples
htmlcssinheritancecustom-element

Why does the % width and height for a shadow element in the shadow root of another customer element not work?


HTML:

<options-container>
  <options-panel panel-type=“login”></options-panel>
</options-container>

Parent custom element styles:

options-container {
  display: inline-flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  height: calc(100vh - 52px);
  height: calc(100vh - (45px + 0.3vw));
  min-height: max(calc(56.25vw - 52px), calc(100vh - 52px));
  min-height: max(calc(56.25vw - (45px + 0.3vw)), calc(100vh - (45px + 0.3vw)));
  position: fixed;
  top: 52px;
  top: calc(45px + 0.3vw);
  right: 0;
  z-index: 1;
  width: calc(300px + 3vw);
  -webkit-backface-visibility: hidden;
  -webkit-perspective: 1000;
  -webkit-transform-style: preserve-3d;
  -webkit-transition: width 0.5s ease-in-out;
  -moz-transition: width 0.5s ease-in-out;
  -o-transition: width 0.5s ease-in-out;
  transition: width 0.5s ease-in-out;
  will-change: width;
  pointer-events: none;
}

Child element (in the shadow root of the above element) styles:

:host {
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
  flex-direction: column;
  width: 90%;
  height: auto;
  max-height: 100vh;
  padding: 10px;
  min-height: 10vw;
  background-color: var(--white, white);
  border: 2px solid var(--light-gray, lightgray);
  border: 0.2vw solid var(--light-gray, lightgray);
  box-sizing: border-box;
  margin-top: 20px;
  border-radius: 10px;
  border-radius: calc(8px + 0.3vw);
  overflow: hidden;
  box-shadow: 0px 0px 10px 0px var(--shadow, black);
  box-shadow: 0px 0px calc(8px + 0.3vw) 0px var(--shadow, black);
  pointer-events: auto;
  animation: fly-down 1.5s ease-out;
  animation-play-state: running;
  -webkit-transform: translate3d(0, 0, 0) !important;
  -webkit-backface-visibility: hidden;
  -webkit-transform-style: preserve-3d;
  -webkit-transition: max-height 0.5s ease-in-out 0.5s;
  -moz-transition: max-height 0.5s ease-in-out 0.5s;
  -o-transition: max-height 0.5s ease-in-out 0.5s;
  transition: max-height 0.5s ease-in-out 0.5s;
  will-change: max-height;
}

Parent Element Box Model

Parent Element Box Model

Child Element Box Model

Child Element Box Model

Having real trouble trying to explain this behaviour, and more trouble trying to get the child element to become visible. I may be missing something really small, I don't know. But any guidance and/or explanation would be greatly appreciated!


Solution

  • Answer found!

    Embarrassing, rookie error, I had attached a shadow root to the <options-container> element, which is why the child elements were not being rendered. Nothing to do with the CSS at all.

    Note to self and others in a similar situation: Check the shadow root.

    Doing

    this.shadowroot = this.attachShadow({mode: 'open'});

    was the answer.