简体   繁体   English

为Angular2中的路由器出口在CSS中设置绝对位置

[英]Set position absolute in css for router-outlet in Angular2

I have a site with this base layout 我有一个具有这种基本布局的网站

  <nav>
    Navcontent
  </nav>
  <router-outlet></router-outlet>

I have a component that is rendered in the router outlet that I want to display on top of the Navcontent. 我在路由器插座中呈现了一个组件,该组件要显示在Navcontent的顶部。 To do this I tried with 为此,我尝试了

.album-select-bar {
  z-index: 100;
  position: absolute;
  top: 0px;
}

<app-album-select-bar class="album-select-bar"></app-album-select-bar>

However, this places the element just below the Navcontent element. 但是,这会将元素放置在Navcontent元素的正下方。 How can I make place the content of the router-outlet on top of Navcontent in Angular2? 如何在Angular2的Navcontent顶部放置路由器出口的内容?

Try using a negative margin, to make it overflow its parent: 尝试使用负边距,使其溢出其父级:

.album-select-bar {
  z-index: 100;
  position: absolute;
  top: 0px;
  height: 50px;
  margin-top: -50px; //should equal height.
}

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

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