Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material column width fit content?

This is my actual Angular Material table:

enter image description here

I would like the column width to fit the content so that the header and the rows content occupy one line.

Tried adding padding and margin with:

.mat-row {
    height: auto;
}

.mat-cell {
    padding: 0px 15px 15px 0;
}

That solution separates the columns, but the content, for example a date, is still in 3 different rows.

How can I solve this?

like image 434
Iñigo Avatar asked Sep 06 '25 22:09

Iñigo


1 Answers

You can override the header cells CSS to force them to be one line :

https://stackblitz.com/edit/angular-sae9ln?file=styles.css

table > thead > tr > th.mat-header-cell.cdk-column-position.mat-column-position {
  white-space: nowrap;
}

Try removing this line in the stackblitz and see what happens


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!