![](/img/trans.png)
[英]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.