4

我正在尝试将我的图像粘贴到

 position: -webkit-sticky;
 position: sticky;
 top: 1px;

但是无法实现。

HTML:

<mat-tab-group class="user-tabs"
    (selectedTabChange)="changeUserTab($event)">
  <mat-tab label="Selectable Tasks">
    <mat-tab-group class="user-chats"
        (selectedTabChange)="changeChatTab($event)">
        <mat-tab *ngFor="let chat of userData.chats; let i = index;">
           <img>
        </mat-tab>
    </mat-tab-group>
  </mat-tab>
</mat-tab-group>

我有标签里面的标签,是的。有人对此有解决方案吗?谢谢。

4

4 回答 4

1

这是一个解决方案:

 <mat-tab-group
      id="my-tab-group"
      mat-stretch-tabs
      [selectedIndex]="tab"
      (selectedIndexChange)="changeTab($event)"
    >
      <mat-tab>
        <custom-component-with-sticky-content></custom-component-with-sticky-content>
      </mat-tab>
      <mat-tab>
        <my-second-component></my-second-component>
      </mat-tab>
 </mat-tab-group>
 ...

和CSS:

 styles: [
     `
  /* Needed in order to allow the sticky content  */
  ::ng-deep #my-tab-group .mat-tab-body-wrapper .mat-tab-body.mat-tab-body-active {
    overflow: visible !important;
  }

  ::ng-deep #my-tab-group .mat-tab-body-wrapper {
    overflow: visible !important;
  }

  ::ng-deep #my-tab-group .mat-tab-body-wrapper .mat-tab-body-content {
    overflow: visible !important;
  }
`,
],
于 2021-05-11T14:36:33.237 回答
0

请尝试 position:fixed 如果需要还添加 z-index:999。

于 2018-10-03T13:52:21.757 回答
0

overflow找到了一个原因 - 当至少有一个父级设置为时它将不起作用,hidden而 mat-tabs 就是这种情况。

于 2018-10-03T17:13:04.650 回答
0

我能够使用 *ngTemplateOutlet 使其工作(以及其他答案的一些帮助,但没有 ngTemplateOutlet 还不够)

HTML:

<div class="main-container" id="main-container">
    <mat-tab-group id="tabs" #tabs>
        <mat-tab label="myTabLabel">    
           (your code here)
        </mat-tab>
    </mat-tab-group>
</div>


<ng-container *ngTemplateOutlet="idek"> </ng-container>


<ng-template #idek>
    <mat-toolbar color="warn" >Second Toolbar</mat-toolbar>
    <div id="add-spacing">
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
        </div>

</ng-template>

CSS:

::ng-deep #tabs .mat-tab-body-wrapper .mat-tab-body.mat-tab-body-active {
    overflow: visible !important;
}

::ng-deep #tabs .mat-tab-body-wrapper {
   overflow: visible !important;
}

::ng-deep #tabs .mat-tab-body-wrapper .mat-tab-body-content {
    overflow: visible !important;
}

mat-toolbar {
    --default-height: 50px !important;
}

mat-toolbar {
    position: sticky !important;
    top: var(--default-height) !important;
}

.main-container {
    (your code here)
}

结果:

在此处输入图像描述

于 2021-10-05T21:23:51.683 回答