Layout

Handling the overall layout of a page.

Specification#

Size#

The first level navigation is inclined left near a logo, and the secondary menu is inclined right.

  • Top Navigation (almost systems): the height of the first level navigation 64px, the second level navigation 48px.
  • Top Navigation(contents page): the height of the first level navigation 80px, the second level navigation 56px.
  • Calculation formula of a top navigation: 48+8n.
  • Calculation formula of an aside navigation: 200+8n.

Interaction rules#

  • The first level navigation and the last level navigation should be distincted by visualization;
  • The current item should have the highest priority of visualization;
  • When the current navigation item is collapsed, the stlye of the current navigation item will be applied to its parent level;
  • The left side navigation bar has support for both the accordion and expanding styles, you can choose the one that fits your case best.

Visualization rules#

Style of a navigation should conform to the its level.

  • Emphasis by colorblock

    When background color is a deep color, you can use this pattern for the parent level navigation item of current page.

  • The highlight match stick

    When background color is a light color, you can use this pattern for the current page navigation item, we recommed using it for the last item of the navigation path.

  • Hightlighted font

    From the visualization aspect, hightlighted font is stronger than colorblock, this pattern is often used for the parent level of the current item.

  • Enlarge the size of the font

    12px14px is a standard font size of navigations,14px is used for the first and the second level of the navigation. You can choose a approprigate font size in terms of the level of your navigation.

Component Overview#

  • nz-layout: The layout wrapper, in which nz-headernz-sidernz-contentnz-footer or nz-layout itself can be nested, and can be placed in any parent container.
  • nz-header: The top layout with default style, in which any element can be nested, and must be placed in nz-layout.
  • nz-sider: The sidebar with default style and basic functions, in which any element can be nested, and must be placed in nz-layout.
  • nz-content: The content layout with default style, in which any element can be nested, and must be placed in nz-layout.
  • nz-footer: The bottom layout with default style, in which any element can be nested, and must be placed in nz-layout.

Based on flex layout, please pay attention to the compatibility.

Examples

HeaderContentFooterHeader
Sider
Content
Footer
HeaderContent
Sider
Footer
Sider
HeaderContentFooter

Classic page layouts.

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-basic',
  template: `
    <nz-layout>
      <nz-header>Header</nz-header>
      <nz-content>Content</nz-content>
      <nz-footer>Footer</nz-footer>
    </nz-layout>

    <nz-layout>
      <nz-header>Header</nz-header>
      <nz-layout>
        <nz-sider>Sider</nz-sider>
        <nz-content>Content</nz-content>
      </nz-layout>
      <nz-footer>Footer</nz-footer>
    </nz-layout>

    <nz-layout>
      <nz-header>Header</nz-header>
      <nz-layout>
        <nz-content>Content</nz-content>
        <nz-sider>Sider</nz-sider>
      </nz-layout>
      <nz-footer>Footer</nz-footer>
    </nz-layout>

    <nz-layout>
      <nz-sider>Sider</nz-sider>
      <nz-layout>
        <nz-header>Header</nz-header>
        <nz-content>Content</nz-content>
        <nz-footer>Footer</nz-footer>
      </nz-layout>
    </nz-layout>
  `,
  styles: [
    `
      :host {
        text-align: center;
      }

      nz-header,
      nz-footer {
        background: #7dbcea;
        color: #fff;
      }

      nz-footer {
        line-height: 1.5;
      }

      nz-sider {
        background: #3ba0e9;
        color: #fff;
        line-height: 120px;
      }

      nz-content {
        background: rgba(16, 142, 233, 1);
        color: #fff;
        min-height: 120px;
        line-height: 120px;
      }

      nz-layout {
        margin-bottom: 48px;
      }

      nz-layout:last-child {
        margin: 0;
      }
    `
  ]
})
export class NzDemoLayoutBasicComponent {}
  • nav 1
  • nav 2
  • nav 3
Home / List / App /
Content
Ant Design ©2019 Implement By Angular

The most basic "header-content-footer" layout.

Generally, the mainnav is placed at the top of the page, and includes the logo, the first level navigation, and the secondary menu (users, settings, notifications) from left to right in it. We always put contents in a fixed size navigation (eg: 1200px), the layout of the whole page is stable, it's not affected by viewing area.

Top-bottom structure is conform with the top-bottom viewing habit, it's a classical navigation pattern of websites. This pattern demonstrates efficiency in the main workarea, while using some vertical space. And because the horizontal space of the navigation is limited, this pattern is not suitable for cases when the first level navigation contains many elements or links

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-top',
  template: `
    <nz-layout class="layout">
      <nz-header>
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'horizontal'" style="line-height: 64px;">
          <li nz-menu-item>nav 1</li>
          <li nz-menu-item>nav 2</li>
          <li nz-menu-item>nav 3</li>
        </ul>
      </nz-header>
      <nz-content style="padding:0 50px;">
        <nz-breadcrumb style="margin:16px 0;">
          <nz-breadcrumb-item>Home</nz-breadcrumb-item>
          <nz-breadcrumb-item>List</nz-breadcrumb-item>
          <nz-breadcrumb-item>App</nz-breadcrumb-item>
        </nz-breadcrumb>
        <div style="background:#fff; padding: 24px; min-height: 280px;">Content</div>
      </nz-content>
      <nz-footer style="text-align: center;">Ant Design ©2019 Implement By Angular</nz-footer>
    </nz-layout>
  `,
  styles: [
    `
      .logo {
        width: 120px;
        height: 31px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px 24px 16px 0;
        float: left;
      }
    `
  ]
})
export class NzDemoLayoutTopComponent {}
  • nav 1
  • nav 2
  • nav 3
  • subnav 1
      • option1
      • option2
      • option3
      • option4
  • subnav 2
      • option5
      • option6
      • option7
      • option8
  • subnav 3
      • option9
      • option10
      • option11
      • option12
Home / List / App / Content

Both the top navigation and the sidebar, commonly used in application site.

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-top-side-2',
  template: `
    <nz-layout class="layout">
      <nz-header>
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'horizontal'" style="line-height: 64px;">
          <li nz-menu-item>nav 1</li>
          <li nz-menu-item>nav 2</li>
          <li nz-menu-item>nav 3</li>
        </ul>
      </nz-header>
      <nz-layout>
        <nz-sider [nzWidth]="200" style="background:#fff">
          <ul nz-menu [nzMode]="'inline'" style="height:100%">
            <li nz-submenu>
              <span title><i nz-icon type="user"></i>subnav 1</span>
              <ul>
                <li nz-menu-item>option1</li>
                <li nz-menu-item>option2</li>
                <li nz-menu-item>option3</li>
                <li nz-menu-item>option4</li>
              </ul>
            </li>
            <li nz-submenu>
              <span title><i nz-icon type="laptop"></i>subnav 2</span>
              <ul>
                <li nz-menu-item>option5</li>
                <li nz-menu-item>option6</li>
                <li nz-menu-item>option7</li>
                <li nz-menu-item>option8</li>
              </ul>
            </li>
            <li nz-submenu>
              <span title><i nz-icon type="notification"></i>subnav 3</span>
              <ul>
                <li nz-menu-item>option9</li>
                <li nz-menu-item>option10</li>
                <li nz-menu-item>option11</li>
                <li nz-menu-item>option12</li>
              </ul>
            </li>
          </ul>
        </nz-sider>
        <nz-layout style="padding:0 24px 24px">
          <nz-breadcrumb style="margin:16px 0;">
            <nz-breadcrumb-item>Home</nz-breadcrumb-item>
            <nz-breadcrumb-item>List</nz-breadcrumb-item>
            <nz-breadcrumb-item>App</nz-breadcrumb-item>
          </nz-breadcrumb>
          <nz-content style="background:#fff; padding: 24px; min-height: 280px;">Content</nz-content>
        </nz-layout>
      </nz-layout>
    </nz-layout>
  `,
  styles: [
    `
      .logo {
        width: 120px;
        height: 31px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px 28px 16px 0;
        float: left;
      }
    `
  ]
})
export class NzDemoLayoutTopSide2Component {}
  • nav 1
  • nav 2
  • nav 3
Home / List / App /
  • subnav 1
      • option1
      • option2
      • option3
      • option4
  • subnav 2
      • option5
      • option6
      • option7
      • option8
  • subnav 3
      • option9
      • option10
      • option11
      • option12
Content
Ant Design ©2019 Implement By Angular

Both the top navigation and the sidebar, commonly used in documentation site.

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-top-side',
  template: `
    <nz-layout class="layout">
      <nz-header>
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'horizontal'" style="line-height: 64px;">
          <li nz-menu-item>nav 1</li>
          <li nz-menu-item>nav 2</li>
          <li nz-menu-item>nav 3</li>
        </ul>
      </nz-header>
      <nz-content style="padding:0 50px;">
        <nz-breadcrumb style="margin:16px 0;">
          <nz-breadcrumb-item>Home</nz-breadcrumb-item>
          <nz-breadcrumb-item>List</nz-breadcrumb-item>
          <nz-breadcrumb-item>App</nz-breadcrumb-item>
        </nz-breadcrumb>
        <nz-layout style="padding:24px 0; background: #fff">
          <nz-sider [nzWidth]="200" style="background:#fff">
            <ul nz-menu [nzMode]="'inline'" style="height:100%">
              <li nz-submenu>
                <span title><i nz-icon type="user"></i>subnav 1</span>
                <ul>
                  <li nz-menu-item>option1</li>
                  <li nz-menu-item>option2</li>
                  <li nz-menu-item>option3</li>
                  <li nz-menu-item>option4</li>
                </ul>
              </li>
              <li nz-submenu>
                <span title><i nz-icon type="laptop"></i>subnav 2</span>
                <ul>
                  <li nz-menu-item>option5</li>
                  <li nz-menu-item>option6</li>
                  <li nz-menu-item>option7</li>
                  <li nz-menu-item>option8</li>
                </ul>
              </li>
              <li nz-submenu>
                <span title><i nz-icon type="notification"></i>subnav 3</span>
                <ul>
                  <li nz-menu-item>option9</li>
                  <li nz-menu-item>option10</li>
                  <li nz-menu-item>option11</li>
                  <li nz-menu-item>option12</li>
                </ul>
              </li>
            </ul>
          </nz-sider>
          <nz-content style="padding: 0 24px; min-height: 280px;">Content</nz-content>
        </nz-layout>
        <nz-footer style="text-align: center;">Ant Design ©2019 Implement By Angular</nz-footer>
      </nz-content>
    </nz-layout>
  `,
  styles: [
    `
      .logo {
        width: 120px;
        height: 31px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px 28px 16px 0;
        float: left;
      }
    `
  ]
})
export class NzDemoLayoutTopSideComponent {}

Two-columns layout. The sider menu can be collapsed when horizontal space is limited.

Generally, the mainnav is placed on the left side of the page, and the secondary menu is placed on the top of the working area. Contents will adapt the layout to the viewing area to improve the horizontal space usage, while the layout of the whole page is not stable.

The level of the aisde navigation is scalable. The first, second, and third level navigations could be present more fluently and relevantly, and aside navigation can be fixed, allowing the user to quickly switch and spot the current position, improving the user experience. However, this navigation occupies some horizontal space of the contents

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-side',
  template: `
    <nz-layout>
      <nz-sider nzCollapsible [(nzCollapsed)]="isCollapsed" [nzWidth]="width" [nzReverseArrow]="isReverseArrow">
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'inline'" [nzInlineCollapsed]="isCollapsed">
          <li nz-submenu>
            <span title><i nz-icon type="user"></i><span class="nav-text">User</span></span>
            <ul>
              <li nz-menu-item>Tom</li>
              <li nz-menu-item>Bill</li>
              <li nz-menu-item>Alex</li>
            </ul>
          </li>
          <li nz-submenu>
            <span title><i nz-icon type="team"></i><span class="nav-text">Team</span></span>
            <ul>
              <li nz-menu-item>Team 1</li>
              <li nz-menu-item>Team 2</li>
            </ul>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="file"></i><span class="nav-text">File</span></span>
          </li>
        </ul>
      </nz-sider>
      <nz-layout>
        <nz-header style="background: #fff; padding:0;"></nz-header>
        <nz-content style="margin:0 16px;">
          <nz-breadcrumb style="margin:16px 0;">
            <nz-breadcrumb-item>User</nz-breadcrumb-item>
            <nz-breadcrumb-item>Bill</nz-breadcrumb-item>
          </nz-breadcrumb>
          <div style="padding:24px; background: #fff; min-height: 360px;">
            Bill is a cat.
          </div>
        </nz-content>
        <nz-footer style="text-align: center;">Ant Design ©2019 Implement By Angular</nz-footer>
      </nz-layout>
    </nz-layout>
  `,
  styles: [
    `
      .logo {
        height: 32px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px;
      }
    `
  ]
})
export class NzDemoLayoutSideComponent {
  isCollapsed = false;
  isReverseArrow = false;
  width = 200;
}
  • User
      • Tom
      • Bill
      • Alex
  • Team
      • Team 1
      • Team 2
  • File
User / Bill /
Bill is a cat.
Ant Design ©2019 Implement By Angular

If you want to use a customized trigger, you can hide the default one by setting trigger={null}.

expand codeexpand code
import { Component, TemplateRef, ViewChild } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-custom-trigger',
  template: `
    <nz-layout>
      <nz-sider nzCollapsible [(nzCollapsed)]="isCollapsed" [nzTrigger]="triggerTemplate">
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'inline'" [nzInlineCollapsed]="isCollapsed">
          <li nz-submenu>
            <span title><i nz-icon type="user"></i><span class="nav-text">User</span></span>
            <ul>
              <li nz-menu-item>Tom</li>
              <li nz-menu-item>Bill</li>
              <li nz-menu-item>Alex</li>
            </ul>
          </li>
          <li nz-submenu>
            <span title><i nz-icon type="team"></i><span class="nav-text">Team</span></span>
            <ul>
              <li nz-menu-item>Team 1</li>
              <li nz-menu-item>Team 2</li>
            </ul>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="file"></i><span class="nav-text">File</span></span>
          </li>
        </ul>
      </nz-sider>
      <nz-layout>
        <nz-header style="background: #fff; padding:0;">
          <i
            class="trigger"
            nz-icon
            [type]="isCollapsed ? 'menu-unfold' : 'menu-fold'"
            (click)="isCollapsed = !isCollapsed"
          ></i>
        </nz-header>
        <nz-content style="margin:0 16px;">
          <nz-breadcrumb style="margin:16px 0;">
            <nz-breadcrumb-item>User</nz-breadcrumb-item>
            <nz-breadcrumb-item>Bill</nz-breadcrumb-item>
          </nz-breadcrumb>
          <div style="padding:24px; background: #fff; min-height: 360px;">
            Bill is a cat.
          </div>
        </nz-content>
        <nz-footer style="text-align: center;">Ant Design ©2019 Implement By Angular</nz-footer>
      </nz-layout>
    </nz-layout>
    <ng-template #trigger>
      <i nz-icon type="up"></i>
    </ng-template>
  `,
  styles: [
    `
      .trigger {
        font-size: 18px;
        line-height: 64px;
        padding: 0 24px;
        cursor: pointer;
        transition: color 0.3s;
      }

      .trigger:hover {
        color: #1890ff;
      }

      .logo {
        height: 32px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px;
      }
    `
  ]
})
export class NzDemoLayoutCustomTriggerComponent {
  isCollapsed = false;
  triggerTemplate: TemplateRef<void> | null = null;
  @ViewChild('trigger') customTrigger: TemplateRef<void>;

  /** custom trigger can be TemplateRef **/
  changeTrigger(): void {
    this.triggerTemplate = this.customTrigger;
  }
}

Layout.Sider supports responsive layout.

Note: You can get a responsive layout by setting nzBreakpoint, the nz-sider will collapse to the width of nzCollapsedWidth when window width is below the nzBreakpoint. And a special trigger will appear if the nzCollapsedWidth is set to 0.

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-responsive',
  template: `
    <nz-layout>
      <nz-sider
        nzCollapsible
        [(nzCollapsed)]="isCollapsed"
        [nzBreakpoint]="'lg'"
        [nzCollapsedWidth]="0"
        [nzZeroTrigger]="zeroTrigger"
      >
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'inline'" [nzInlineCollapsed]="isCollapsed">
          <li nz-menu-item>
            <span><i nz-icon type="user"></i><span class="nav-text">nav 1</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="video-camera"></i><span class="nav-text">nav 2</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="upload"></i><span class="nav-text">nav 3</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="user"></i><span class="nav-text">nav 4</span></span>
          </li>
        </ul>
      </nz-sider>
      <nz-layout>
        <nz-header style="background: #fff; padding:0;"></nz-header>
        <nz-content style="margin:24px 16px 0;">
          <div style="padding:24px; background: #fff; min-height: 360px;">
            Content
          </div>
        </nz-content>
        <nz-footer style="text-align: center;">Ant Design ©2019 Implement By Angular</nz-footer>
      </nz-layout>
    </nz-layout>
    <ng-template #zeroTrigger>
      <i nz-icon type="menu-fold" theme="outline"></i>
    </ng-template>
  `,
  styles: [
    `
      .logo {
        height: 32px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px;
      }
    `
  ]
})
export class NzDemoLayoutResponsiveComponent {
  isCollapsed = false;
}

Fixed Header is generally used to fix the top navigation to facilitate page switching.

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-fixed',
  template: `
    <nz-layout class="layout">
      <nz-header style="position:fixed; width:100%">
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'horizontal'" style="line-height: 64px;">
          <li nz-menu-item>nav 1</li>
          <li nz-menu-item>nav 2</li>
          <li nz-menu-item>nav 3</li>
        </ul>
      </nz-header>
      <nz-content style="padding:0 50px;margin-top:64px;">
        <nz-breadcrumb style="margin:16px 0;">
          <nz-breadcrumb-item>Home</nz-breadcrumb-item>
          <nz-breadcrumb-item>List</nz-breadcrumb-item>
          <nz-breadcrumb-item>App</nz-breadcrumb-item>
        </nz-breadcrumb>
        <div style="background:#fff; padding: 24px; min-height: 380px;">Content</div>
      </nz-content>
      <nz-footer style="text-align: center;">Ant Design ©2019 Implement By Angular</nz-footer>
    </nz-layout>
  `,
  styles: [
    `
      .logo {
        width: 120px;
        height: 31px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px 24px 16px 0;
        float: left;
      }
    `
  ]
})
export class NzDemoLayoutFixedComponent {}

When dealing with long content, a fixed sider can provide a better user experience.

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-layout-fixed-sider',
  template: `
    <nz-layout>
      <nz-sider style="overflow: auto; height: 100vh; position: fixed; left: 0">
        <div class="logo"></div>
        <ul nz-menu [nzTheme]="'dark'" [nzMode]="'inline'">
          <li nz-menu-item>
            <span><i nz-icon type="file"></i><span class="nav-text">nav 1</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="video-camera"></i><span class="nav-text">nav 2</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="upload"></i><span class="nav-text">nav 3</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="bar-chart"></i><span class="nav-text">nav 4</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="cloud-o"></i><span class="nav-text">nav 5</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="appstore-o"></i><span class="nav-text">nav 6</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="team"></i><span class="nav-text">nav 7</span></span>
          </li>
          <li nz-menu-item>
            <span><i nz-icon type="shop"></i><span class="nav-text">nav 8</span></span>
          </li>
        </ul>
      </nz-sider>
      <nz-layout style="margin-left: 200">
        <nz-header style="background: #fff; padding:0;"></nz-header>
        <nz-content style="margin:24px 16px 0;overflow: initial">
          <div style="padding: 24px; background: #fff; text-align: center">
            ...
            <br />
            Really
            <br />...<br />...<br />...<br />
            long
            <br />...<br />...<br />...<br />...<br />...<br />...
            <br />...<br />...<br />...<br />...<br />...<br />...
            <br />...<br />...<br />...<br />...<br />...<br />...
            <br />...<br />...<br />...<br />...<br />...<br />...
            <br />...<br />...<br />...<br />...<br />...<br />...
            <br />...<br />...<br />...<br />...<br />...<br />... <br />...<br />...<br />...<br />...<br />...<br />
            content
          </div>
        </nz-content>
        <nz-footer style="text-align: center;">Ant Design ©2019 Implement By Angular</nz-footer>
      </nz-layout>
    </nz-layout>
  `,
  styles: [
    `
      .logo {
        height: 32px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px;
      }
    `
  ]
})
export class NzDemoLayoutFixedSiderComponent {}

API#

<nz-layout>
  <nz-header>header</nz-header>
  <nz-layout>
    <nz-sider>left sidebar</nz-sider>
    <nz-content>main content</nz-content>
    <nz-sider>right sidebar</nz-sider>
  </nz-layout>
  <nz-footer>footer</nz-footer>
</nz-layout>

Import this Component Individually#

You can get more detail here.

import { NzLayoutModule } from 'ng-zorro-antd';

nz-sider#

The sidebar.

PropertyDescriptionTypeDefault
[nzBreakpoint]breakpoints of the responsive layout'xs'|'sm'|'md'|'lg'|'xl'|'xxl'-
[nzCollapsed]to set the current statusboolean-
[nzCollapsedWidth]width of the collapsed sidebar, by setting to 0 a special trigger will appearnumber64
[nzCollapsible]whether can be collapsedbooleanfalse
[nzCollapsed]the collapsed status can be double bindingbooleanfalse
[nzReverseArrow]reverse direction of arrow, for a sider that expands from the rightbooleanfalse
[nzTrigger]specify the customized trigger, set to null to hide the triggerstring|TemplateRef<void>-
[nzZeroTrigger]specify the customized trigger when nzCollapsedWidth setting to 0TemplateRef<void>-
[nzWidth]width of the sidebarnumber|string200
[nzTheme]color theme of the sidebar'light'|'dark'dark
(nzCollapsedChange)the callback functionEventEmitter<boolean>-

breakpoint width#

{
  xs: '480px',
  sm: '768px',
  md: '992px',
  lg: '1200px',
  xl: '1600px',
  xxl: '1600px'
}