【问题标题】:How to reduce nebular side bar width?如何减小星云侧边栏宽度?
【发布时间】:2020-04-05 14:31:01
【问题描述】:

我正在使用 ngx-admin 并且有一个关于如何动态减小侧边栏大小的问题。此外,当我最小化浏览器时,侧边栏应根据浏览器大小自动调整大小。 (它应该是响应式的)。

【问题讨论】:

    标签: nebular ngx-admin


    【解决方案1】:

    您可以在 github 上找到我对 ngx-admin 演示代码的回答的实时示例。 因此,您可以使用 nebular 中包含的 layoutService 来使侧边栏具有响应性。示例:

      <nb-sidebar class="menu-sidebar" tag="menu-sidebar" responsive>
        <nb-menu [items]="YourItems"></nb-menu>
      </nb-sidebar>
    

    然后制作一个按钮以在展开、压缩和折叠之间切换。 这是用于切换和自动处理响应的按钮及其代码。

    <a (click)="toggleSidebar()" class="sidebar-toggle">
                <nb-icon icon="menu-2-outline"></nb-icon>
            </a>
    

    然后在你的 ts 文件中使用布局服务:

     import { NbSidebarService } from '@nebular/theme';
      import { LayoutService } from '../../@core/utils';
    
    
    constructor(private layoutService: LayoutService, private sidebarService:NbSidebarService){}
    
    toggleSidebar() {
        this.sidebarService.toggle(true, 'menu-sidebar');
        this.layoutService.changeLayoutSize();
        return false;
      }
    

    最后决定侧边栏宽度只需将它们与变量一起注册到默认主题示例:

    @import "~@nebular/theme/styles/theming";
    @import "~@nebular/theme/styles/themes/default";
    
    $nb-themes: nb-register-theme(
      (
         sidebar-width: 16rem,
         sidebar-width-compact: 3.5rem
      ),
      default,
      default
    );
    

    【讨论】:

      【解决方案2】:

      我找到了自己的答案。我将文件 one-column.layout.scss 更改为此。

         @import '../../styles/themes';
         @import '~bootstrap/scss/mixins/breakpoints';
         @import '~@nebular/theme/styles/global/breakpoints';
      
         @include nb-install-component() {
             .menu-sidebar ::ng-deep .scrollable {
                 padding-top: nb-theme(layout-padding-top);
            }
         }
      
         @include nb-install-component() {
            .menu-sidebar ::ng-deep .main-container.main-container-fixed {
                width: 10rem;
          }
        }
      
        @include nb-install-component() {
         .expanded {
              width: 10rem;
         }
       }
      

      并将文件 one-column.layout.ts 更改为此

      import { AfterViewInit, Component, Inject, PLATFORM_ID, ViewChild } from '@angular/core';
      import { isPlatformBrowser } from '@angular/common';
      import { NbLayoutComponent } from '@nebular/theme';
      import { WindowModeBlockScrollService } from '../../services/window-mode-block-scroll.service';
      
      @Component({
      selector: 'ngx-one-column-layout',
      styleUrls: ['./one-column.layout.scss'],
      template: `
       <nb-layout windowMode>
         <nb-layout-header fixed>
           <ngx-header></ngx-header>
         </nb-layout-header>
      
        <nb-sidebar state="expanded" class="menu-sidebar" style="width: 'auto'" tag="menu-sidebar" responsive>
          <ng-content select="nb-menu"></ng-content>
        </nb-sidebar>
      
        <nb-layout-column>
          <ng-content select="router-outlet"></ng-content>
        </nb-layout-column>
      
        <nb-layout-footer fixed>
          <ngx-footer></ngx-footer>
        </nb-layout-footer>
      </nb-layout> ` })
      
          export class OneColumnLayoutComponent implements AfterViewInit {
           @ViewChild(NbLayoutComponent, { static: false }) layout: NbLayoutComponent;
      
          constructor(
           @Inject(PLATFORM_ID) private platformId,
           private windowModeBlockScrollService: WindowModeBlockScrollService) {}
      
         ngAfterViewInit() {
          if (isPlatformBrowser(this.platformId)) {
            this.windowModeBlockScrollService.register(this.layout);
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2023-03-30
        • 1970-01-01
        • 2013-10-16
        • 1970-01-01
        • 1970-01-01
        • 2016-12-23
        • 2020-06-02
        • 2014-10-28
        • 2017-12-06
        相关资源
        最近更新 更多