为什么另一个客户元素的影子根中的影子元素的宽度和高度百分比不起作用?

问题描述

HTML:

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

父级自定义元素样式:

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;
}

子元素(在上述元素的阴影根中)的样式:

: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) !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

子元素框模型

Child Element Box Model

在尝试解释这种行为时遇到了真正的麻烦,而在试图使子元素变得可见方面遇到了更多的麻烦。我可能会丢失一些很小的东西,我不知道。但是任何指导和/或解释将不胜感激!

解决方法

找到答案!

令人尴尬的菜鸟错误,我在<options-container>元素上附加了阴影根,这就是为什么未渲染子元素的原因。与CSS完全无关。

在类似情况下,请注意self和其他人:检查影子根。

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

是答案。