将面包屑固定到标头

时间:2019-09-23 14:23:16

标签: css angular bootstrap-4

我想将面包屑固定在导航栏顶部。使用有角度的引导程序4开发应用程序。

app.component.html

<nav class="navbar navbar-expand-lg navbar-toggleable-lg navbar-dark bg-dark sticky-top" style="position:sticky">
  <!--navbar-expand-sm navbar-dark bg-dark sticky-top -->


  <!-- Important - make sure to have the toggler button outside of the container -->
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse">
    <!--aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"-->
    <span class="navbar-toggler-icon"></span>
  </button>
  <div>

    <span class="navbar-text" style="color:white">Header</span>
  </div>
</nav>

<div class="container-fluid" style="padding-left:0px;">
  <div class="row">
    <div class="col-12 col-xl-2 col-lg-3 col-md-4">
      <div class="col-xl-12 col-lg-12 col-md-12 x1-sidebar bg-dark" style="position:sticky;">
        <app-navbar></app-navbar>
      </div>
    </div>
    <div class="col">
      <router-outlet></router-outlet>
    </div>
  </div>
</div>

app-navbar是一个垂直导航组件。

路由器出口是主要内容。它具有动态面包屑和内容。

下面是面包屑和内容:

<div class="container">
    <div class="row" *ngIf="breadCrumbs?.length>0" style="position:inherit;">
        <div class="col">
            <nav aria-label="breadcrumb">
                <ul class="breadcrumb bg-dark sticky-top" >
                    <li class="breadcrumb-item" *ngFor='let breadcrumb of breadCrumbs; let i = index' >
                        <a >{{ Dynamic breadcrumb label }}</a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
    <div class="row">
        <div class="col">
            //content.......
        </div>
    </div>
</div>

让我知道代码是否不清楚。我会提供更多信息。

1 个答案:

答案 0 :(得分:0)

将此添加到CSS:

.breadcrumb {
    position: fixed;
    top: 40px;
    width: 100%;
}

然后根据标题的高度,在该代码中调整40px的值。