简体   繁体   English

样式组件选择器DOM元素

[英]Style component selector DOM element

I've got a component hierarchy: 我有一个组件层次结构:

appParent.html
    <app-parent>
      <div class="someDiv"> // has width and height set
        <app-child></app-child>
      </div>
    </app-parent>

appChild.html: appChild.html:

  <div class="childWrapper"></div>

I would like to style app-child to have width an height equal to its container. 我想给app-child设置样式,使其宽度等于其容器的高度。 My ultimate goal is to have .childWrapper the same width and height as .someDiv , but I do not want to bring JS into business 我的最终目标是让.childWrapper相同的宽度和高度.someDiv ,但我不希望把JS下海经商

I applied 我申请了

app-child{
  width:100%;
  height:100%;
}

but app-child remains 0x0px . app-child仍为0x0px I tried setting some random width and heights and app-child remains 0x0px at all times. 我尝试设置一些随机宽度和高度, app-child始终保持0x0px Applying styles to .someDiv works as expected. 将样式应用于.someDiv可以正常工作。

What is going on here? 这里发生了什么? Why can't styles be applied to component selectors? 为什么不能将样式应用于组件选择器?

Given the above CSS on the child, it IS taking up 100% of the parent's height. 鉴于上面关于孩子的CSS,它占据了父母身高的100%。 The problem is that the parent does not have an explicit height set. 问题在于父级没有设置明确的高度。 Try setting the height of someDiv. 尝试设置someDiv的高度。

See this codepen: Full height child div 看到这个codepen: 全高子div

.someDiv {
    border:1px solid red;
    height:100px;
    width:200px;
}

.childWrapper {
    border: 1px solid blue; 
    width:100%;
    height:100%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM