我正在制作Angular Material网页。我<mat-icon>
在中的标题文本旁边添加了一个<mat-table>
。添加完垫图标后,图标和文本未完全对齐。图标未垂直居中,看起来有点过高。标题文本与其他列文本不对齐,看起来有点低。
我得到的最接近的是我在带有文本的标签内移动了mat-icon的情况。
这是我的代码
<table mat-table [dataSource]="dataSource">
<ng-container matColumnDef="column1">
<th mat-header-cell *matHeaderCellDef style="text-align: center !important" [attr.colspan]="2"><h2>Column 1</h2></th>
</ng-container>
<ng-container matColumnDef="column2">
<th *matHeaderCellDef style="text-align: center !important" [attr.colspan]="2">
<h2><mat-icon class="pointer" style="padding-bottom: 0px; padding-right: 1px; cursor: pointer;" >arrow_left</mat-icon>Column 2</h2>
</th>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedGroupColumns; sticky: true"></tr>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table >
您对细节的关注让人想起我在工作的客户;
为了实现这一点,我们使用position:absolute
,但将其括在div中,position:relative
以免脱离网格
相关的CSS:
.myCustomHeading{position:relative;padding-top:4px;}
.myIcon{position:relative;}
.mySpan{position:absolute;padding-top:2px;}
相关的HTML:
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> <h2>No.</h2> </th>
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>
<div class='myCustomHeading'>
<h2><mat-icon class="pointer myIcon" >arrow_left</mat-icon>
<span class="mySpan">Column 2</span></h2>
</div>
</th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句