【问题标题】:Using angular2/4 material, How to use mat-chip with text next to chips on each row?使用 angular2/4 材料,如何在每行芯片旁边使用带有文本的 mat-chip?
【发布时间】:2018-08-12 17:11:40
【问题描述】:

使用 angular2/4,我想在单个芯片旁边使用带有文本的 mat-chip (https://material.angular.io/components/chips/overview),并让它占据每个“条目”的整个宽度(div 中的单行)。其他条目应显示在彼此下方,就像正在运行的聊天一样。现在我有:

我目前的代码如下,但是看起来并没有达到预期的效果……

<div class="rectanglebox" style="width:300px;height:500px;">
<div style="float:left">
<mat-chip-list>
  <mat-chip>A</mat-chip>
</mat-chip-list>
</div>
<div style="float:left">Text for A that is really long and may overflow. If it does, the chip should remain to the left side and not move all the text to a new dedicated line.</div>
</div>
</div>
<div style="float:left">
<mat-chip-list>
  <mat-chip>B</mat-chip>
</mat-chip-list>
</div>
<div style="float:left">Text for B</div>
</div>
<div style="float:left">
<mat-chip-list>
  <mat-chip>C</mat-chip>
</mat-chip-list>
</div>
<div style="float:left">Text for C</div>
</div>

使用示例显示所有文本如果太长而不是环绕在芯片“下方”,则该示例如何: https://stackblitz.com/edit/angular-ijhhz3-fn56yj?file=app/chips-overview-example.html

【问题讨论】:

    标签: html css angular


    【解决方案1】:

    您可以将style="display: inline-block" 用于要显示的 div,我已经修改了您的 HTML,您可以在此处查看,固定 div 您需要使用 css 的 postion 属性。我已经使用position: absolute 了解更多信息,您可以查看here

     <div class="rectanglebox" style="width:300px;height:500px;">
    <div style="display: inline-block;position: absolute;">
    <mat-chip-list>
      <mat-chip>A</mat-chip>
    </mat-chip-list>
    </div>
    <div style="display: inline-block;margin-left: 45px;">Text for A where something is super long that ehrere sids sdis fdf ds f sdf sd fs d fs fsd f s fsd f sf df s fs fd Text for A where something is super long that ehrere sids sdis fdf ds f sdf sd fs d fs fsd f s fsd f sf df s fs fd Text for C long that ehrere sids sdis fdf ds f sdf sd fs d fs fsd f s fsd f sf df s fs fd margin-left: 45px;</div>
    
    <div>
    <div style="display: inline-block;position: absolute;">
    <mat-chip-list aria-orientation="vertical"> 
      <mat-chip>B</mat-chip>
    </mat-chip-list>
    </div>
    <div style="display: inline-block;margin-left: 45px;">Text for B Text for A where something is super long that ehrere sids sdis fdf ds f sdf sd fs d fs fsd f s fsd f sf df s fs fd margin-left: 45px;</div>
    </div>
    <div style="display: inline-block;position: absolute;">
    <mat-chip-list>
      <mat-chip>C</mat-chip>
    </mat-chip-list>
    </div>
    <div style="display: inline-block;margin-left: 45px;" >Text for C long that ehrere sids sdis fdf ds f sdf sd fs d fs fsd f s fsd f sf df s fs fd margin-left: 45px;</div>
    </div>
    

    看看here

    【讨论】:

    • 这个问题是如果“A 的文本”变得很长,所有的文本都转到下一行,并且芯片与中间对齐。有没有办法让芯片始终保持在左侧,并且 div 中的所有文本都不会跳到芯片下方?
    • 您好,您需要为您的 div 设置位置位置将固定,绝对您的 div,我已使用绝对设置 div A 的位置。您可以在这里查看stackblitz.com/edit/angular-ijhhz3-yahv46?file=app/…
    • 这可行,但要求“芯片”不超过特定宽度,否则必须更改边距。可以说没有办法根据芯片宽度进行调整吗?
    • 是的,您也可以根据芯片宽度进行调整。为此,您还需要设置文本宽度。
    猜你喜欢
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 2021-06-20
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    相关资源
    最近更新 更多