首页 > 解决方案 > 为什么另一个客户元素的阴影根中的阴影元素的百分比宽度和高度不起作用?

问题描述

HTML:

<options-container>
  <options-panel panel-type=“login”&gt;</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, 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;
}

父元素框模型

父元素框模型

子元素盒模型

子元素盒模型

在试图解释这种行为时遇到了真正的麻烦,而试图让子元素变得可见则更加困难。我可能错过了一些非常小的东西,我不知道。但任何指导和/或解释将不胜感激!

标签: htmlcssinheritancecustom-element

解决方案


找到答案了!

令人尴尬的菜鸟错误,我在元素上附加了一个阴影根<options-container>,这就是子元素没有被渲染的原因。根本与 CSS 无关。

类似情况的自己和其他人注意:检查影子根。

正在做

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

是答案。


推荐阅读