响应式导航栏在角度内容上重叠

时间:2018-09-03 12:14:42

标签: html css angular responsive

我有nav如下

<nav class="navbar navbar-expand-sm navbar-light navbar-fixed-top ">
    <!-- <a class="navbar-brand" href="#"></a> -->
    <button class="navbar-toggler" (click)="collapse=!collapse" type="button" aria-expanded="false" aria-label="Toggle navigation">
        <span #tasknote class="navbar-toggler-icon"></span>
    </button>

    <div class="navbar-collapse" (click)="collapse=true" [hidden]="collapse">
        <ul class="navbar-nav mr-auto sub-menu dl-submenu">
            <li class="nav-item menu-item">
                <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item menu-item">
                <a class="nav-link" href="#">About</a>
            </li>
            <li class="nav-item menu-item">
                <a class="nav-link" href="#">first</a>
            </li>

        </ul>

    </div>
</nav>

和其余内容部分,如下所示

<div>
//some content here
</div>

当我单击Navabar-toggler时,它在响应内容上重叠。 我们如何在Angle 4项目中进行纠正

1 个答案:

答案 0 :(得分:2)

您可以通过以下方式实现

component.ts

classIsSet=false
toggleClass()
  {
   this.classIsSet=!this.classIsSet;
  }

component.html

<nav class="navbar navbar-expand-sm navbar-light navbar-fixed-top ">
    <button class="navbar-toggler" (click)="collapse=!collapse" type="button" aria-expanded="false" aria-label="Toggle navigation"
        (click)="toggleClass()">
        <span #tasknote class="navbar-toggler-icon"></span>
    </button>

    <div class="navbar-collapse" (click)="collapse=true" [hidden]="collapse">
        <ul class="navbar-nav mr-auto sub-menu dl-submenu">
            <li class="nav-item menu-item">
                <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item menu-item">
                <a class="nav-link" href="#">About</a>
            </li>
             <li class="nav-item menu-item">
                    <a class="nav-link" href="#">first</a>
                </li>
        </ul>
    </div>
</nav>

//内容部分

<div [ngClass]="{'res-nav':!classIsSet,'res-nav':classIsSet}">
//your required content
</dv>

component.css

.res-nav{
margin-top: 200px;//your required top size
}

希望它将解决您的问题!!