gpt4 book ai didi

Angular Material 选项卡将图像添加到按钮

转载 作者:太空狗 更新时间:2023-10-29 17:23:49 25 4
gpt4 key购买 nike

我是 Angular 的初学者。我尝试使用 Angular material tab 做一些事情。我将选项卡部分添加到图像,但该部分不起作用。有谁知道如何将图像添加到 Angular Material 选项卡。请查看我所附的图片以了解我试图实现的目标。

Need like this

My code so far (stackblitz demo)

我的代码部分:

<mat-tab-group mat-stretch-tabs class="example-stretched-tabs mat-elevation-z4">
<mat-tab label="First" style="background:url('/assets/img/school-01.png')"> Content 1 </mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>

CSS

.example-stretched-tabs {
max-width: 800px;
}
/* active tab */
.mat-tab-list .mat-tab-labels .mat-tab-label-active {
color:#0f2241;
background-color: #535353;
opacity: 1;
}

/* ink bar */
.mat-tab-group.mat-primary .mat-ink-bar {
background: none;
content: url('https://image.flaticon.com/icons/svg/60/60995.svg');
height: 10px;
}

.ts

import {Component, ViewEncapsulation} from '@angular/core';

/**
* @title Tab group with stretched labels
*/
@Component({
selector: 'tab-group-stretched-example',
templateUrl: 'tab-group-stretched-example.html',
styleUrls: ['tab-group-stretched-example.css'],
encapsulation: ViewEncapsulation.None
})
export class TabGroupStretchedExample {}

最佳答案

根据Angular docs :

For more complex labels, add a template with the mat-tab-label directive inside the mat-tab.

所以你可以把你的 <img>或任何你想要的模板 <ng-template mat-tab-label/> .

<mat-tab-group>
<mat-tab>
<ng-template mat-tab-label>
<img src="...">
<span>foo</span>
</ng-template>
</mat-tab>
<mat-tab>
....
</mat-tab>
</mat-tab-group>

关于 Angular Material 选项卡将图像添加到按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52325669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com