10

I want to modify the default look of Angular Material Paginator. For example, I want to change the justify-content property to flex-start.

.mat-paginator-container {
display: flex;
align-items: center;
justify-content: flex-end;
min-height: 56px;
padding: 0 8px;
flex-wrap: wrap-reverse;
width: 100%;}

What I did was- I pasted the css below in styles.css file

.mat-paginator-container {
display: flex;
align-items: center;
justify-content: flex-start;
min-height: 56px;
padding: 0 8px;
flex-wrap: wrap-reverse;
width: 100%;}

But that didn't work. I also tried the css in the component's css file. But that also didn't work. So how can I modify the css ?

UPDATE

Turns out that I had to use !important and it worked!. I was avoiding that that but had no other choice. Any better solutions, then please let me know.

4
  • a minimal example on stackblitz which recreates the issue will help everyone assist on this Commented Dec 10, 2018 at 6:16
  • Make sure and verify in console (inspect) whether your style has been added or still overwritten by some other class. As said by AlqbalRaj, stackblitz will help us to find where you are missing. Commented Dec 10, 2018 at 6:19
  • 1
    @AIqbalRaj for some reasons, I am only able to change the background color of the paginator. Every other css gets overridden. Commented Dec 10, 2018 at 6:39
  • Same problem here. Commented Feb 12, 2019 at 8:39

3 Answers 3

8

you can use ::ng-deep to change the style of mat-paginator

:host ::ng-deep.mat-paginator .mat-paginator-container{
  justify-content: flex-start;
}

Without using ::ng-deep( for Angular 8+ )

Turn off encapsulation of your component inside which you change the padding.

You can do this by

 import {Component,ViewEncapsulation} from '@angular/core';
 @Component({
   selector: 'example',
   templateUrl: 'example.component.html',
   styleUrls: ['example.component.css'],
   encapsulation : ViewEncapsulation.None,
 })
 export class ExampleComponent {}

Wrap the component you want to style in a custom class. So it wont affect any other mat-paginator components.

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

2 Comments

sorry, Its because wrong class name. It should be .mat-paginator instead of .paginator. I had edited it in the answer.
Unfortunately doesn't work (no longer works?) with AM 8
1

By adding !important in css, I didn`t succeed. So I did this in app.component.css file:

.mat-paginator {
     display: flex;
     justify-content: center;
 }

But you might complain that probably you don`t want the paginator to be "flex". You can put the hole paginator in a div tag to make sure that it will be shown as a block:

In app.component.html:

  ...
     <div class="container">
         <mat-paginator>
              ......
         </mat-paginator>
     </div>
  ... 


PS: Adding !important is NOT a good idea.

Comments

1

You should put ::ng-deep before the class selector:

::ng-deep .mat-paginator-container {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 56px;
  padding: 0 8px;
  flex-wrap: wrap-reverse;
  width: 100%;
}

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.