简体   繁体   English

如何设置Angular material tab的mat-ink-bar取tab header text width的宽度

[英]How to set the Angular material tab's mat-ink-bar to take the width of tab header text width

I want the Angular material tab's mat-ink-bar to take the width of the tab header text's width.我希望 Angular 材质选项卡的垫墨栏采用选项卡 header 文本宽度的宽度。 Currently, it is larger than the tab header text width.目前,它大于选项卡 header 文本宽度。

The following image shows how it looks now.下图显示了它现在的样子。

当前外观

The following image shows how I want it to be.下图显示了我想要的样子。

我希望 mat-tab-ink-bar 看起来如何

Could you help me how to make this happen?你能帮我怎么做吗?

在此处输入图片说明 I achieved this by removing min-width and padding on the .mat-tab-label class.. and adding margin as per my requirement to keep the labels apart.我通过删除 .mat-tab-label 类上的 min-width 和 padding 来实现这一点......并根据我的要求添加边距以保持标签分开。 this worked as mat-ink-bar takes the width of mat-tab-label which was set min-width to 160px;这是因为 mat-ink-bar 采用了 mat-tab-label 的宽度,将 min-width 设置为 160px;

SCSS:社会保障:

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;
    }
    }
}
}

I have done it using after and before css pseudo classes, but for cutting a definite amount of the mat-ink-bar width.我已经在 css 伪类之后和之前完成了它,但是为了减少一定数量的 mat-ink-bar 宽度。 Please see the below SCSS code请参阅下面的 SCSS 代码

  mat-ink-bar {           
                &:before,
                &:after {
                    content: "";
                    height: 2px;
                    width: 20px;
                    background-color: white;
                    position: absolute;
                    left: 0;
                }
                &:after {
                    left: initial;
                    right: 0;
                }
            }

Simply remove the background color of existing mat-link-bar (using background-color: transparent ) and create a new style using pseudo class.只需删除现有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;
        }
      }

Looks like this:看起来像这样:

在此处输入图片说明

In later versions of Angular Material (currently 15) you now have the option to use the fitInkBarToContent attribute.在 Angular Material 的更高版本(当前为 15)中,您现在可以选择使用fitInkBarToContent属性。

<mat-tab-group fitInkBarToContent>
  <mat-tab label="Tab">Content</mat-tab>
</mat-tab-group>

See the examples under https://material.angular.io/components/tabs/examples#tab-group-ink-bar请参阅https://material.angular.io/components/tabs/examples#tab-group-ink-bar下的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM