Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

horizontal only webkit scrollbar style css

Tags:

jquery

css

webkit

this is custom scrollbar in css

 /* Gmail style scrollbar */
 ::-webkit-scrollbar {
   width: 12px
 }
 ::-webkit-scrollbar-thumb {
   border-width: 1px 1px 1px 2px
 }
 ::-webkit-scrollbar-track {
   border-width: 0
 }
 ::-webkit-scrollbar {
   height: 16px;
   overflow: visible;
   width: 16px;
 }
 ::-webkit-scrollbar-button {
   height: 0;
   width: 0;
 }
 ::-webkit-scrollbar-track {
   background-clip: padding-box;
   border: solid transparent;
   border-width: 0 0 0 4px;
 }
 ::-webkit-scrollbar-track:horizontal {
   border-width: 4px 0 0
 }
 ::-webkit-scrollbar-track:hover {
   background-color: rgba(220, 172, 0, .05);
   box-shadow: inset 1px 0 0 rgba(220, 172, 0, .1);
 }
 ::-webkit-scrollbar-track:horizontal:hover {
   box-shadow: inset 0 1px 0 rgba(220, 172, 0, .1)
 }
 ::-webkit-scrollbar-track:active {
   background-color: rgba(220, 172, 0, .05);
   box-shadow: inset 1px 0 0 rgba(220, 172, 0, .14), inset -1px 0 0 rgba(220, 172, 0, .07);
 }
 ::-webkit-scrollbar-track:horizontal:active {
   box-shadow: inset 0 1px 0 rgba(220, 172, 0, .14), inset 0 -1px 0 rgba(220, 172, 0, .07)
 }
 ::-webkit-scrollbar-thumb {
   background-color: rgba(220, 172, 0, .2);
   background-clip: padding-box;
   border: solid transparent;
   border-width: 1px 1px 1px 6px;
   min-height: 28px;
   padding: 100px 0 0;
   box-shadow: inset 1px 1px 0 rgba(220, 172, 0, .1), inset 0 -1px 0 rgba(220, 172, 0, .07);
 }
 ::-webkit-scrollbar-thumb:horizontal {
   border-width: 6px 1px 1px;
   padding: 0 0 0 100px;
   box-shadow: inset 1px 1px 0 rgba(220, 172, 0, .1), inset -1px 0 0 rgba(220, 172, 0, .07);
 }
 ::-webkit-scrollbar-thumb:hover {
   background-color: rgba(220, 172, 0, .4);
   box-shadow: inset 1px 1px 1px rgba(220, 172, 0, .25);
 }
 ::-webkit-scrollbar-thumb:active {
   background-color: rgba(220, 172, 0, 0.5);
   box-shadow: inset 1px 1px 3px rgba(220, 172, 0, 0.35);
 }
 ::-webkit-scrollbar-track {
   border-width: 0 1px 0 6px
 }
 ::-webkit-scrollbar-track:horizontal {
   border-width: 6px 0 1px
 }
 ::-webkit-scrollbar-track:hover {
   background-color: rgba(220, 172, 0, .035);
   box-shadow: inset 1px 1px 0 rgba(220, 172, 0, .14), inset -1px -1px 0 rgba(220, 172, 0, .07);
 }
 ::-webkit-scrollbar-thumb {
   border-width: 0 1px 0 6px
 }
 ::-webkit-scrollbar-thumb:horizontal {
   border-width: 6px 0 1px
 }
 ::-webkit-scrollbar-corner {
   background: transparent
 }
 body::-webkit-scrollbar-track-piece {
   background-clip: padding-box;
   background-color: #f5f5f5;
   border: solid #fff;
   border-width: 0 0 0 3px;
   box-shadow: inset 1px 0 0 rgba(220, 172, 0, .14), inset -1px 0 0 rgba(220, 172, 0, .07);
 }
 body::-webkit-scrollbar-track-piece:horizontal {
   border-width: 3px 0 0;
   box-shadow: inset 0 1px 0 rgba(220, 172, 0, .14), inset 0 -1px 0 rgba(220, 172, 0, .07);
 }
 body::-webkit-scrollbar-thumb {
   border-width: 1px 1px 1px 5px
 }
 body::-webkit-scrollbar-thumb:horizontal {
   border-width: 5px 1px 1px
 }
 body::-webkit-scrollbar-corner {
   background-clip: padding-box;
   background-color: #f5f5f5;
   border: solid #fff;
   border-width: 3px 0 0 3px;
   box-shadow: inset 1px 1px 0 rgba(220, 172, 0, .14);
 }
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris   placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus   enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis   luctus, metus</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris   placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus   enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis   luctus, metus</p>

I use the above code to beautify my scroll bar, but I do not want to style my vertical bar.

I tried to remove the tags which don't contain 'horizontal' but it doesn't work.

like image 294
user3106579 Avatar asked Dec 20 '13 23:12

user3106579


People also ask

How do I style a horizontal scrollbar in CSS?

For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.

How do I customize my horizontal scroll bar?

Scrollbar Selectors For webkit browsers, you can use the following pseudo elements to customize the browser's scrollbar: ::-webkit-scrollbar the scrollbar. ::-webkit-scrollbar-button the buttons on the scrollbar (arrows pointing upwards and downwards). ::-webkit-scrollbar-thumb the draggable scrolling handle.

How do I fix the horizontal scrollbar in CSS?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.

Can I use ::- webkit scrollbar?

You can use the following pseudo-elements to customize various parts of the scrollbar for WebKit browsers: ::-webkit-scrollbar — the entire scrollbar. ::-webkit-scrollbar-button — the buttons on the scrollbar (arrows pointing upwards and downwards that scroll one line at a time).


2 Answers

For horizontal scroll bar set height

    ::-webkit-scrollbar{     width: 12px;     height: 12px;     } 
like image 165
user2357975 Avatar answered Sep 23 '22 16:09

user2357975


Once you've set the css for

::-webkit-scrollbar{} 

both the horizontal and vertical bars are automatically affected.

If you want the horizontal bar to look different from the vertical bar, you will have to set separate CSS for each, like this:

::-webkit-scrollbar-thumb:horizontal {     background-color:#5B0B2B; } ::-webkit-scrollbar-thumb:horizontal:hover{     background-color:#B31252;     border: solid 1px #5B0B2B; }  ::-webkit-scrollbar-thumb:vertical {     background-color:#2A8894; } ::-webkit-scrollbar-thumb:vertical:hover {     background-color:#32BFD1;     border: solid 1px #2A8894; } 

Here's a complete JSFiddle Demo.

like image 32
ITWitch Avatar answered Sep 25 '22 16:09

ITWitch