2

I want to create a responsive Top Navigation using Angular Nebular theme. I created the top menu using

<nb-layout-header fixed>
    <nb-actions class="left">
        <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-action *ngIf="local.retrieve('loggedIn')">secret menu2</nb-action>
    </nb-actions>
</nb-layout-header>

But it's same layout in both PC and mobile. How could i make the top navigation bar become a 'hamburger' menu when user browse in mobile like reference below

https://www.w3schools.com/howto/howto_js_topnav_responsive.asp

Weilies
  • 500
  • 1
  • 7
  • 27

1 Answers1

2

it's a problem of css and mediaQuery. There're severals ways, a simple, you defined two .css button-responsive and menu-responsive

.button-responsive
{
    display:none
}

@media (max-width: 573px)
{
    .button-responsive
    {
        display:inline-block
    }
    .menu-responsive
    {
        display:none
    }
}

Then you can has a nb-actions and a 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>

Update the same tecnique using a fixed sideBar For this in constructor of the component

constructor(public sidebarService: NbSidebarService) {}

And our .html becomes like

<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>
Eliseo
  • 50,109
  • 4
  • 29
  • 67
  • SALUTE!!! Your code so INSPIRING! although i quit nebular and use PrimeNG, but it gave me ideas and even helped me how to make the things work in PrimeNG!! Impressive! – Weilies May 28 '20 at 16:28