gpt4 book ai didi

html - 响应式导航栏以 Angular 重叠在内容上

转载 作者:行者123 更新时间:2023-11-27 23:01:27 29 4
gpt4 key购买 nike

我有 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 时,它会重叠响应式内容。我们如何在 Angular 4 元素中进行整改

最佳答案

可以通过以下方式实现

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>

组件.css

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

希望它能解决你的问题!!

关于html - 响应式导航栏以 Angular 重叠在内容上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52149625/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com