这是css和mediaQuery的问题。有几种方法,一种简单的方法,你定义了两种.css按钮响应和菜单响应
.button-responsive
{
display:none
}
@media (max-width: 573px)
{
.button-responsive
{
display:inline-block
}
.menu-responsive
{
display:none
}
}
然后你可以有一个nb操作和一个nbContextMenu
<nb-layout-header fixed>
<!--add class button-responsive to the button-->
<button nbButton ghost class="button-responsive" [nbContextMenu]="allitems">
<nb-icon icon="menu-outline"></nb-icon>
</button>
<!--add class menu-responsive to nb-actions-->
<nb-actions class="left menu-responsive">
<nb-action class="profile" [nbContextMenu]="items" nbContextMenuPlacement="bottom">Profile</nb-action>
<nb-action [routerLink]="['/login']">Login</nb-action>
<nb-action>menu 1</nb-action>
<nb-action>menu 2</nb-action>
<nb-action>secret menu</nb-action>
</nb-actions>
</nb-layout-header>
更新
使用固定侧杆的相同技术
为此,在组件的构造函数中
constructor(public sidebarService: NbSidebarService) {}
我们的.html变成了这样
<nb-layout>
<nb-layout-header fixed>
<nb-icon class="button-responsive" icon="menu-outline" (click)="sidebarService.toggle()"></nb-icon>
<nb-actions class="left menu-responsive">
<nb-action class="profile" [nbContextMenu]="items" nbContextMenuPlacement="bottom">Profile</nb-action>
<nb-action [routerLink]="['/login']">Login</nb-action>
<nb-action>menu 1</nb-action>
<nb-action>menu 2</nb-action>
<nb-action>secret menu</nb-action>
</nb-actions>
</nb-layout-header>
<nb-sidebar #sidebar state="collapsed" class="button-responsive" fixed>
<nb-menu [items]="items"></nb-menu>
</nb-sidebar>