如何使Angular材料自动完成中的2个span左右对齐,不翻译代码部分。

huangapple go评论105阅读模式
英文:

how to make 2 span under mat-option to have left and right align in angular material auto complete

问题

Here is the translated code portion you provided:

  1. <mat-form-field class="example-full-width">
  2. <input #stateInput (keyup)="0" matInput placeholder="State" aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
  3. <mat-autocomplete #auto="matAutocomplete">
  4. <mat-option (onSelectionChange)="stateInput.value !=undefined && onEnter($event)" *ngFor="let state of filteredStates | async" [value]="state.name">
  5. <img style="vertical-align:middle;" aria-hidden src="{{state.flag}}" height="25" />
  6. <span>{{ state.name }}</span> |
  7. <span>Population: {{state.population}}</span>
  8. </mat-option>
  9. </mat-autocomplete>
  10. </mat-form-field>

Please note that the code is the same as the original, but with HTML entities for special characters to ensure correct rendering.

英文:

i am using angular material auto complete, here i have option dropdown where i have 2 span 1st span must be left align and 2nd span to be left, i tried with absolute position setting to 2nd span but responsiveness gives issue.

Html:

  1. <mat-form-field class="example-full-width">
  2. <input #stateInput (keyup)="0" matInput placeholder="State" aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
  3. <mat-autocomplete #auto="matAutocomplete">
  4. <mat-option (onSelectionChange)="stateInput.value !=undefined && onEnter($event)" *ngFor="let state of filteredStates | async" [value]="state.name">
  5. <img style="vertical-align:middle;" aria-hidden src="{{state.flag}}" height="25" />
  6. <span>{{ state.name }}</span> |
  7. <span>Population: {{state.population}}</span>
  8. </mat-option>
  9. </mat-autocomplete>
  10. </mat-form-field>

Demo

答案1

得分: 1

将这些跨度包装到另一个标签中,然后对该新标签应用display:flexjustify-content:space-between

您还需要将跨度宽度扩展到新标签和Material的.mat-option-text,例如,我应用了width:100%以占用整个可用空间。

这里是您的代码更新。

英文:

You should wrap the spans into another tag, then apply the display:flex and justify-content:space-betweeen to that new tag.

You also need to stretch the span width to both the new tag and the Material .mat-option-text, I applied a width:100% for instance to take the whole space available.

Here is your code updated.

huangapple
  • 本文由 发表于 2023年4月13日 14:55:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76002477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定