1

I am trying to add the border on top and bottom in the header of the table, but somehow its not showing it in angular material table.

<table mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="id">
    <th mat-header-cell *matHeaderCellDef > No. </th>
    <td mat-cell *matCellDef="let order"> {{order.id}} </td>
  </ng-container>
  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>

I use the following CSS

th.mat-header-row {
 border-bottom: 2px solid #ffa600;
 border-top: 2px solid #ffa600;
}
5
  • Do you want something like this ibb.co/YjJXdGF? Commented Mar 6, 2020 at 13:20
  • Use !!mportant to overrule materials css. border-bottom: 2px solid #ffa600 !important; Commented Mar 6, 2020 at 13:37
  • @Mridul Yes i want to have borders like that, can you please tell me how to do that. Thanks Commented Mar 6, 2020 at 13:40
  • @uahmed, I've added the code Commented Mar 6, 2020 at 16:11
  • @Uahmed, Did it work? Commented Mar 7, 2020 at 15:04

3 Answers 3

2

I tried this and it worked on my MatTable

th.mat-header-cell {
border-bottom: 2px solid #ffa600;
border-top: 2px solid #ffa600;
} 
Sign up to request clarification or add additional context in comments.

Comments

1

Below both solutions are working for me. Try these.

table .mat-header-row {
  border-bottom: 2px solid #ffa600;
  border-top: 2px solid #ffa600;
}

OR

::ng-deep .mat-header-row {
  border-bottom: 2px solid #ffa600;
  border-top: 2px solid #ffa600;
}

Comments

0

Add a class demo to your HTML like:

<tr mat-header-row class="demo" *matHeaderRowDef="displayedColumns"></tr>

And use the following CSS:

.demo{
    border-bottom: 2px solid #ffa600;
    border-top: 2px solid #ffa600;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.