简体   繁体   English

mat-tab-group 宽度对 flex 中宽度为 100% 的容器没有反应

[英]mat-tab-group width is not reacting to width 100% container in flex

currently I am working on a project which contains a flexbox design in which a mat-tab-group .目前我正在开发一个包含 flexbox 设计的项目,其中有一个mat-tab-group The problem I am facing is, it does not properly react to the parents width and it seems only the max-width property in the .parameters class influences the width.我面临的问题是,它不能正确响应父宽度,似乎只有.parameters类中的max-width属性会影响宽度。

<div class="flex-container">
  <!-- there are other elements in here -->
  <div class="flex-item">
    <div class="parameters">
      <form [formGroup]="form">
        <mat-tab-group mat-stretch-tabs>
          <!-- tabs placed here -->
        </mat-tab-group>
      </form>
    </div>
  </div>
</div>

Removing the mat-stretch-tabs property does not help neither.删除mat-stretch-tabs属性也无济于事。 Using a pixel value as flex-basis should make the width calculations independent of the content.使用像素值作为 flex-basis 应该使宽度计算独立于内容。 But as soon as there are more tabs than the targeted width allows, the content will be as wide as the mat-tab-group .但是,只要标签的数量超过目标宽度允许的数量,内容就会与mat-tab-group一样宽。 The styling of the above structure looks like上面结构的样式看起来像

.flex-container {
  display: flex;
}

.flex-item {
  flex: 1 1 250px;
}

.parameters {
  overflow: hidden;     /* tested, no impact */
  min-width: 0;         /* tested, no impact */
  max-width: 350px;     /* working but always 350px */
}

also I tested a {width: 100%} property on the mat-tab-group but it has no impact neither.我还在mat-tab-group上测试了{width: 100%}属性,但它也没有影响。 The following removes the horizontal scroll at all (and it uses /deep/ which I would like to avoid).以下内容完全删除了水平滚动(并且它使用了我想避免的/deep/ )。

/deep/.mat-tab-label, /deep/.mat-tab-label-active{
  min-width: 0!important;
  padding: 3px!important;
  margin: 3px!important;
}

Do you have any ideas?你有什么想法? What am I missing?我错过了什么?

It's not a problem with mat-tab-group, but with flexbox default settings, where flex item can't be smaller that its content.这不是 mat-tab-group 的问题,而是 flexbox 默认设置的问题,其中 flex item 不能小于它的内容。

min-width: 0; for flexbox item overrides it. for flexbox 项目覆盖它。

kudos to this answer这个答案

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

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