Mat-Chips连续显示5

发布于 2025-02-02 19:36:09 字数 862 浏览 1 评论 0原文

我有一个Mat-Chips列表,我正在尝试通过倍数行显示它们。我想连续有5个芯片,而芯片的尺寸不增加(例如,有一个标准值,例如100px)。如果行上有一个元素,那将需要我不想要的整个宽度。我尝试了弹性的基础,但这是行不通的。我该怎么做?

HTML:

    <div class="chip" fxLayoutAlign="flex-start">
        <mat-form-field class="example-chip-list" appearance="fill">
  <mat-label>Favorite Fruits</mat-label>
  <mat-chip-list #chipList aria-label="Fruit selection">
    <mat-chip *ngFor="let fruit of fruits" id="chip-item" (removed)="remove(fruit)">
      {{fruit.name}}
      <button matChipRemove>
        <mat-icon>cancel</mat-icon>
      </button>
    </mat-chip>
  </mat-chip-list>
</mat-form-field>
    </div>

CSS:

.chip {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
}

#chip-item {
    flex: 1 0 25%;
}

I have a list of mat-chips and I'm trying to display them over multiples rows. I want to have 5 chips on a row and chip's size to don't increase (have a standard value, for example 100px). If there was one element on the row, it would take the whole width which I don't want. I tried with flex basis, but it's doesn't work. How can I do it?

HTML:

    <div class="chip" fxLayoutAlign="flex-start">
        <mat-form-field class="example-chip-list" appearance="fill">
  <mat-label>Favorite Fruits</mat-label>
  <mat-chip-list #chipList aria-label="Fruit selection">
    <mat-chip *ngFor="let fruit of fruits" id="chip-item" (removed)="remove(fruit)">
      {{fruit.name}}
      <button matChipRemove>
        <mat-icon>cancel</mat-icon>
      </button>
    </mat-chip>
  </mat-chip-list>
</mat-form-field>
    </div>

CSS:

.chip {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
}

#chip-item {
    flex: 1 0 25%;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文