Styling scrollbars within Ionic mode in Ionic 6: A step-by-step guide
P粉547362845
P粉547362845 2024-01-04 20:51:07
0
1
452

ion-modal has a default scrollbar that appears if the content overflows. I want to style the scrollbar.

I can style the scrollbar in the application using ::-webkit-scrollbar, ::-webkit-scrollbar-track and ::-webkit-scrollbar-thumb, but it doesn't seem to work in modal. I tried applying these elements to multiple components inside the modal, such as ion-content::-webkit-scrollbar, but it doesn't work.

P粉547362845
P粉547362845

reply all(1)
P粉670107661

Here's the general way to style scrollbars within Ionic mode in Ionic 6.

  1. Wrap the ionic mode content inside

Tag as shown below

<ion-content>
    //modal content goes here
</ion-content>
  1. Then add the following css of the scrollbar in the global css file

    ion-content {
         --offset-bottom: auto !important;
         --overflow: auto;
         background: var(--ion-toolbar-background, var(--ion-background-color, 
                      #000000)) !important;
         overflow: auto;
    
     &::-webkit-scrollbar {
         width: 5px;
         height: 5px;
     }
    
     &::-webkit-scrollbar-track {
         background: rgb(0, 0, 0);
     }
    
     &::-webkit-scrollbar-track:hover {
         background: #35d703;
     }
    
     &::-webkit-scrollbar-thumb {
         background: rgb(75, 75, 75);
     }
    
      &::-webkit-scrollbar-thumb:hover {
          background: #94173a
      }
    
      .inner-scroll {
          scrollbar-width: thin;
      }
    }

Your scrolling will look like this in ion-modal

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!