我在Angular应用程序中有一个Boostrap 4导航栏,外部<div>
关联。随着BS3的出现就像魅力一样,但是对于BS4,一些行为似乎有所改变。特别是我遇到了.collapse
课程的问题。
使用BS3,当我加载页面时,显示外部div,但是对于BS4,它最初是隐藏的。此外,当我调整页面大小时,外部div会自动与导航栏一起折叠,而使用BS4则不会。[/ p>
所以我的问题是:我必须做些什么才能拥有与Boostrap 3相同的行为?
这是我的代码:
<nav class="navbar navbar-expand-lg navbar-light px-0 py-0 mb-5">
<div class="container-fluid">
<div class="navbar-header" style="width: 100%">
<button type="button" class="navbar-toggler pull-right my-2" data-toggle="collapse" data-target=".navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="pull-left">
<img src="assets/images/image.png" width="200" height="100">
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="btn welcome"> Benvenuto <strong>{{ this.sessionUsername }}</strong>!</a></li>
<li class="nav-item"><a class="btn link" role="button" [routerLink]="['/login']" (click)="clearSessionStorage()"><i class="fa fa-sign-out"></i> Logout</a></li>
<li class="nav-item"><a class="btn link" role="button" data-toggle="modal" data-target="#changePasswordModal"><i class="fa fa-unlock-alt"></i> Cambio Password</a></li>
</ul>
</div>
</div>
</nav>
=== External div that give me troubles in responsiveness ===
<div class="navbar-collapse collapse col-lg-2 col-md-2 col-sm-3 col-xs-12" style="float: left">
<ul class="nav nav-pills flex-column">
<li class="nav-item" *ngIf="session.isCompanyVisible"><a class="nav-link link" [routerLink]="['./company']"><i class="fa fa-building-o"></i> Società </a></li>
<li class="nav-item" *ngIf="session.isDocTypeVisible"><a class="nav-link link" [routerLink]="['./document-type']"><i class="fa fa-file-text-o"></i> Tipo Documento </a></li>
<li class="nav-item" *ngIf="session.isConfigVisible"><a class="nav-link link" [routerLink]="['./configuration']"><i class="fa fa-cog"></i> Configurazione </a></li>
<li class="nav-item" *ngIf="session.isDomainsVisible"><a class="nav-link link" [routerLink]="['./domains']"><i class="fa fa-dot-circle-o"></i> Domini </a></li>
<li class="nav-item" *ngIf="session.isSignTypeVisible"><a class="nav-link link" [routerLink]="['./signature-type']"><i class="fa fa-pencil"></i> Firme </a></li>
<li class="nav-item" *ngIf="session.isMonitoringVisible"><a class="nav-link link" [routerLink]="['./monitoring']"><i class="fa fa-desktop"></i> Monitoraggio </a></li>
<li class="nav-item" *ngIf="session.isPDAManagementVisible"><a class="nav-link link" [routerLink]="['./pda-management']"><i class="fa fa-mobile fa-lg"></i> Gestione PDA </a></li>
</ul>
</div>
答案 0 :(得分:1)
因为bootstarp的css发生了变化 因此,您可以通过将一些css应用到外部div来解决您的问题,因为我在代码段中应用了
@media (min-width: 992px){
.external-collapse.navbar-collapse {
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
}
}
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light px-0 py-0 mb-5">
<div class="container-fluid">
<div class="navbar-header" style="width: 100%">
<button type="button" class="navbar-toggler pull-right my-2" data-toggle="collapse" data-target=".navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="pull-left">
<img src="assets/images/image.png" width="200" height="100">
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="btn welcome"> Benvenuto <strong>{{ this.sessionUsername }}</strong>!</a></li>
<li class="nav-item"><a class="btn link" role="button" [routerLink]="['/login']" (click)="clearSessionStorage()"><i class="fa fa-sign-out"></i> Logout</a></li>
<li class="nav-item"><a class="btn link" role="button" data-toggle="modal" data-target="#changePasswordModal"><i class="fa fa-unlock-alt"></i> Cambio Password</a></li>
</ul>
</div>
</div>
</nav>
=== External div that give me troubles in responsiveness ===
<div class="external-collapse navbar-collapse collapse col-lg-2 col-md-2 col-sm-3 col-xs-12" style="float: left">
<ul class="nav nav-pills flex-column">
<li class="nav-item" *ngIf="session.isCompanyVisible"><a class="nav-link link" [routerLink]="['./company']"><i class="fa fa-building-o"></i> Società </a></li>
<li class="nav-item" *ngIf="session.isDocTypeVisible"><a class="nav-link link" [routerLink]="['./document-type']"><i class="fa fa-file-text-o"></i> Tipo Documento </a></li>
<li class="nav-item" *ngIf="session.isConfigVisible"><a class="nav-link link" [routerLink]="['./configuration']"><i class="fa fa-cog"></i> Configurazione </a></li>
<li class="nav-item" *ngIf="session.isDomainsVisible"><a class="nav-link link" [routerLink]="['./domains']"><i class="fa fa-dot-circle-o"></i> Domini </a></li>
<li class="nav-item" *ngIf="session.isSignTypeVisible"><a class="nav-link link" [routerLink]="['./signature-type']"><i class="fa fa-pencil"></i> Firme </a></li>
<li class="nav-item" *ngIf="session.isMonitoringVisible"><a class="nav-link link" [routerLink]="['./monitoring']"><i class="fa fa-desktop"></i> Monitoraggio </a></li>
<li class="nav-item" *ngIf="session.isPDAManagementVisible"><a class="nav-link link" [routerLink]="['./pda-management']"><i class="fa fa-mobile fa-lg"></i> Gestione PDA </a></li>
</ul>
</div>