How to change the scrollbar styles in Angular Material select?

懵懂的女人 提交于 2019-12-21 09:17:11

问题


We need help in changing the scrollbar in the Select component from Angular Material.

The following demo was implemented.

https://stackblitz.com/angular/bxbvndrpogl?file=app%2Fselect-reset-example.ts

However, I need help in changing the width and style of the scrollbar.

Example


回答1:


Usually the way to customize the scroll is:

/* width */
::-webkit-scrollbar {
    width: 20px;
}

/* Track */
::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px grey; 
    border-radius: 10px;
}

/* Handle */
::-webkit-scrollbar-thumb {
    background: red; 
    border-radius: 10px;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
    background: #b30000; 
}

You cannot directly inspect the scroll from the dev tools, however you can see the styling of it if you inspect the div that has the overflow property with the scroll; value in it.




回答2:


I hope I am not late, I had a similar problem with the native scroll bar.

The way I would solve this problem is to use Simple bar library then I would made directive and only wrap

 <mat-select placeholder="State">
    <div appSimpleBar>
       <mat-option>None</mat-option>
       <mat-option *ngFor="let state of states" [value]="state">{{state}}</mat-option>
    </div>
  </mat-select>

This will do the trick of hiding native scroll bar



来源:https://stackoverflow.com/questions/51610619/how-to-change-the-scrollbar-styles-in-angular-material-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!