最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - How to prevent rotated mat-table headers from being overlapped by adjacent columns? - Stack Overflow

programmeradmin1浏览0评论

In my Angular app, I’m using mat-table with some long column names. To improve readability, I applied a rotate(-30deg) transformation to the header labels. However, this causes the labels to be overlapped by the next column’s div, instead of appearing on top.

I tried setting the parent z-index to 1 and the span's z-index to 99, but with no success.

How can I ensure that the rotated headers are properly displayed above adjacent columns?

<table
  mat-table
  [dataSource]="dataSource"
  multiTemplateDataRows
  class="mat-elevation-z0"
>
  <ng-container *ngFor="let column of displayedColumns" [matColumnDef]="column">
    <th mat-header-cell *matHeaderCellDef class="header-class">
      <span class="rotated-span">
        {{ column }}
      </span>
    </th>
    <td mat-cell *matCellDef="let element">
      {{ element[column] }}
    </td>
  </ng-container>

  <!-- Header and Row -->
  <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
.rotated-span {
      position: absolute;
      height: 10px;
      transform: rotate(-30deg);
      transform-origin: center left;
      white-space: nowrap;
      z-index: 99 !important;
    }
    
.header-class {
    height: 100px;
    background-color: white;
    z-index: 1 !important;
}

发布评论

评论列表(0)

  1. 暂无评论