最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How could I change background-color of the dropdown of mat-paginator? - Stack Overflow

programmeradmin1浏览0评论
    <mat-paginator
        #paginator
        class="table-paginator"
        (page)="handlePageEvent($event)"
        [length]="paginatorLength"
        [pageSize]="paginatorPageSize"
        [showFirstLastButtons]="paginatorShowFirstLastButtons"
        [pageSizeOptions]="paginatorShowPageSizeOptions ? paginatorPageSizeOptions : []"
        [hidePageSize]="paginatorHidePageSize"
        [pageIndex]="paginatorPageIndex">
    </mat-paginator>
::ng-deep .mat-select-panel .mat-option.mat-selected:not(.mat-option-multiple) {
  background: #02a10e !important;
}
::ng-deep .mat-form-field.mat-focused .mat-form-field-ripple {
  background-color: #04c431 !important;
}

I try this code, but it does not changed the background color of the dropdown, how could I change it?

    <mat-paginator
        #paginator
        class="table-paginator"
        (page)="handlePageEvent($event)"
        [length]="paginatorLength"
        [pageSize]="paginatorPageSize"
        [showFirstLastButtons]="paginatorShowFirstLastButtons"
        [pageSizeOptions]="paginatorShowPageSizeOptions ? paginatorPageSizeOptions : []"
        [hidePageSize]="paginatorHidePageSize"
        [pageIndex]="paginatorPageIndex">
    </mat-paginator>
::ng-deep .mat-select-panel .mat-option.mat-selected:not(.mat-option-multiple) {
  background: #02a10e !important;
}
::ng-deep .mat-form-field.mat-focused .mat-form-field-ripple {
  background-color: #04c431 !important;
}

I try this code, but it does not changed the background color of the dropdown, how could I change it?

Share Improve this question edited Mar 18 at 14:02 Naren Murali 60.4k5 gold badges44 silver badges78 bronze badges asked Mar 18 at 13:42 Juan GarciaJuan Garcia 253 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use the below CSS variables to customize the color, since there is no inbuilt customization available in pagination - styling page.

The problem with this approach is that the CSS might break when you upgrade to higher versions of angular material, but that is the same for all non standard ways of customizing material components.

.custom-dropdown-color {
  --mat-sys-secondary-container: #02a10e !important;
  --mat-option-selected-state-layer-color: #04c431 !important;
}

Then we use the panelClass property of MatPaginatorSelectConfig which has the input selectConfig.

Adding the class is important since, we can customize the dropdown specific to a particular component.

<mat-paginator
[length]="100"
[pageSize]="10"
[pageSizeOptions]="[5, 10, 25, 100]"
aria-label="Select page"
[selectConfig]="{panelClass: 'custom-dropdown-color'}"
>
</mat-paginator>

Stackblitz Demo

发布评论

评论列表(0)

  1. 暂无评论