search

Home  >  Q&A  >  body text

Styling scrollbars within Ionic mode in Ionic 6: A step-by-step guide

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粉547362845P粉547362845367 days ago523

reply all(1)I'll reply

  • P粉670107661

    P粉6701076612024-01-05 09:42:15

    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

    reply
    0
  • Cancelreply