[英]How To Style Mat-Ink-Bar with Different Color for Each Mat-Tab In Angular Material?
[英]How to set the Angular material tab's mat-ink-bar to take the width of tab header text width
我通过删除 .mat-tab-label 类上的 min-width 和 padding 来实现这一点......并根据我的要求添加边距以保持标签分开。 这是因为 mat-ink-bar 采用了 mat-tab-label 的宽度,将 min-width 设置为 160px;
社会保障:
mat-tab-header {
border-bottom: none !important;
.mat-tab-label-container {
margin-bottom: 12px;
.mat-tab-labels {
.mat-tab-label {
padding: 0 0 !important;
min-width: 10px;
margin-left: 95px;
}
}
}
}
我已经在 css 伪类之后和之前完成了它,但是为了减少一定数量的 mat-ink-bar 宽度。 请参阅下面的 SCSS 代码
mat-ink-bar {
&:before,
&:after {
content: "";
height: 2px;
width: 20px;
background-color: white;
position: absolute;
left: 0;
}
&:after {
left: initial;
right: 0;
}
}
只需删除现有mat-link-bar
background-color: transparent
(使用background-color: transparent
)并使用pseudo
类创建新样式。
.mat-ink-bar {
background-color: transparent;
&::before {
content: '';
display: block;
width: 90%;
background-color: #47a1f6;
height: 6px;
border-bottom-right-radius: 70px;
border-bottom-left-radius: 70px;
left: 5%;
position: relative;
}
}
看起来像这样:
在 Angular Material 的更高版本(当前为 15)中,您现在可以选择使用fitInkBarToContent
属性。
<mat-tab-group fitInkBarToContent>
<mat-tab label="Tab">Content</mat-tab>
</mat-tab-group>
请参阅https://material.angular.io/components/tabs/examples#tab-group-ink-bar下的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.