2

How can I add space(margin) between header and body in a angular material table?

I tried at first with this solution but it didn't work.

demo: https://stackblitz.com/edit/angular-ivy-anphrw?file=src/app/app.component.html

playerone
  • 987
  • 3
  • 22
  • 44
  • I don't know if it's possible but it's not the way to go: https://material.angular.io/guide/customizing-component-styles. Maybe implement your own table-component that has the features you need. – h0p3zZ Apr 26 '22 at 17:46
  • When you refer to header, are you referring to the bolded elements in your code? (ex. driver ID, Speed, etc..) – Peter Missick Apr 28 '22 at 05:52

5 Answers5

2

What you have seen here can work.

You must add modifiers in order to apply the style to material elements such as :host and ::ng-deep.

Then don't forget to play with the line-height attribute to modify the space between header and body.

This can be controversial because of supposed future deprecation and similarity with !important but it works well, and while you know what you do, it's not a bad thing to use them in my opinion.

I have forked your stackblitz project with the modifiers.

And here is a course for those modifiers, to understand how and when to use them.

Alexis
  • 1,685
  • 1
  • 12
  • 30
1

You need to write your css in style.css

tbody:before {
  content: '\200C';
  display: block;
  line-height: 5rem;
  text-indent: -99999px;
}

example

Bansi29
  • 1,053
  • 6
  • 24
0

Try adding this style:

th {
    padding-bottom: 50px !important;
}
vals
  • 61,425
  • 11
  • 89
  • 138
0

Try to add an height to your thead like this in your css :

thead {
  height: 120px;
 }
Ethan0079
  • 51
  • 8
0
table thead {
  border-bottom: 15px solid transparent;
}
sweetnandha cse
  • 705
  • 7
  • 16