4

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?

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

The columns auto adjust if you don't provide fixed width, i think the problem with your design is that the table does not has enough room to expand.

1 Comment

True, but there's a way

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.