【问题标题】:Styling .toolbar-container of ion-toolbar shadow dom in ionic 4+在 ionic 4+ 中设置 ion-toolbar shadow dom 的 .toolbar-container
【发布时间】:2021-04-01 13:25:50
【问题描述】:

我尝试了很多方法。但不工作。 期待这样的风格

ion-toolbar {
    contain: none;
    .toolbar-container {
        overflow: visible;  // not working
        contain: none;  // not working
    }
}

你有什么解决办法吗?

【问题讨论】:

    标签: css ionic-framework dom sass ionic4


    【解决方案1】:

    我使用新指令解决了这个问题:

    ng generate directive allow-overflow

    import { Directive, ElementRef } from '@angular/core';
    
    @Directive({
      selector: '[appAllowOverflow]'
    })
    export class AllowOverflowDirective {
    
      constructor(el: ElementRef)
      {
        let toolbar : HTMLElement = el.nativeElement;
        setTimeout(() => {
          let container : HTMLElement = toolbar.shadowRoot.querySelector(".toolbar-container");
          if (container)
          {
            // (as any) is just to suppress a warning
            (container.style as any).contain = "none";
            container.style.overflow = "visible";
          }
        });
      }
    }
    

    然后我像这样添加了<ion-toolbar>

    <ion-toolbar appAllowOverflow>
        ...
    </ion-toolbar>
    

    我还为 &lt;ion-toolbar&gt; 添加了这条 CSS 规则:

    ion-toolbar[appAllowOverflow]
    {
      contain: none;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 1970-01-01
      • 2019-06-18
      • 2020-03-03
      • 2019-12-19
      • 2016-03-14
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多