Skip to content

Instantly share code, notes, and snippets.

@Ralphkay
Forked from SaraSoueidan/scrollbar-mixin
Last active July 4, 2018 07:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ralphkay/258d9af45301d368e0b8 to your computer and use it in GitHub Desktop.
Save Ralphkay/258d9af45301d368e0b8 to your computer and use it in GitHub Desktop.
Sass mixin for styling scrollbars in webkit by Hugo Giraudel (http://codepen.io/HugoGiraudel/pen/KFDuB)
/**
* Mixin scrollbar
*/
@mixin scrollbar($size, $primary, $secondary: lighten($primary, 25%)) {
::-webkit-scrollbar {
width: $size;
height: $size;
}
::-webkit-scrollbar-thumb {
background: $primary;
}
::-webkit-scrollbar-track {
background: $secondary;
}
// For Internet Explorer
body {
scrollbar-face-color: $primary;
scrollbar-track-color: $secondary;
}
}
/**
* Call the damn thing
*/
@include scrollbar(.5em, tomato);
/**
* Force scrollbars
*/
body {
height: 3000px;
width: 3000px;
}
@Ralphkay
Copy link
Author

I think probably the body css rules are not entirely needed necessary as they easily apply the styles to any scrollbar in the website. Great mixin!!!

@alpatovdanila
Copy link

Actually doesn't work until you add & symbol before ::-webkit... rules to reference the selector you are applying the mixin to. After that, works like charm

webpack4 sass-loader on win10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment