我正在尝试将我的图像粘贴到
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>
我的选项卡里面有选项卡,是的。有人对此有解决方案吗?谢谢。
解决方案如下:
<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;
}
`,
],
我能够使用 *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)
}
结果:
请尝试position:fixed,如果需要的话还可以添加z-index:999。
找到了一个原因 - 当至少一个父级将
overflow
设置为 hidden
时,它将不起作用,这就是 mat-tabs 的情况。
Angular 15+(mdc 迁移后)
HTML:
<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>
CSS:
::ng-deep #my-tab-group .mat-mdc-tab-body-wrapper .mat-mdc-tab-body.mat-mdc-tab-body-active {
overflow: visible !important;
}
::ng-deep #my-tab-group .mat-mdc-tab-body-wrapper {
overflow: visible !important;
}
::ng-deep #my-tab-group .mat-mdc-tab-body-wrapper .mat-mdc-tab-body-content {
overflow: visible !important;
}