Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position a div scrollbar on the left hand side?

Tags:

html

css

Is it possible to specify a position (left or right hand side) for the placement of a vertical scrollbar on a div?

For example look at this page which explains how to use the overflow attribute. Is there some way of placing that scrollbar on the left hand side of the scrollable area?

like image 301
Andrew Fielden Avatar asked Sep 08 '11 11:09

Andrew Fielden


People also ask

How do I change the position of my scroll bar?

We can use the CSS “::-webkit-scrollbar” property which is responsible for changing the shape, color, size, shade, shadow, etc. of the scroll bar. But, here the property which we will use is the direction property of CSS for changing the position of the scroll bar.

How do you get the scroll bar position?

To get or set the scroll position of an element, you follow these steps: First, select the element using the selecting methods such as querySelector() . Second, access the scroll position of the element via the scrollLeft and scrollTop properties.


2 Answers

You could try direction:rtl; in your css. Then reset the text direction in the inner div

#scroll{     direction:rtl;      overflow:auto;      height:50px;      width:50px;}  #scroll div{     direction:ltr; } 

Untested.

like image 180
Jason Gennaro Avatar answered Oct 21 '22 05:10

Jason Gennaro


  .list_container {     direction: rtl;     overflow:auto;     height: 50px;     width: 50px;   }    .item_direction {     direction:ltr;   }
<div class="list_container">   <div class="item_direction">1</div>   <div class="item_direction">2</div>   <div class="item_direction">3</div>   <div class="item_direction">4</div>   <div class="item_direction">5</div>   <div class="item_direction">6</div>   <div class="item_direction">7</div>   <div class="item_direction">8</div>   <div class="item_direction">9</div>   <div class="item_direction">10</div>   <div class="item_direction">11</div>   <div class="item_direction">12</div> </div>

Working Example: JSFiddle

or

Cut and paste solution that works for all major browsers (Even Safari)

Any height or width will work

<style>   .list_container {     direction: rtl;     overflow:auto;     height: 50px;     width: 50px;   }    .item_direction {     direction:ltr;   } </style> <div class="list_container">   <div class="item_direction">1</div>   <div class="item_direction">2</div>   <div class="item_direction">3</div>   <div class="item_direction">4</div>   <div class="item_direction">5</div>   <div class="item_direction">6</div>   <div class="item_direction">7</div>   <div class="item_direction">8</div>   <div class="item_direction">9</div>   <div class="item_direction">10</div>   <div class="item_direction">11</div>   <div class="item_direction">12</div> </div> 

Optionally add class="item_direction to each item to change the direction of the text flow back, while preserving the container direction.

like image 32
jasonleonhard Avatar answered Oct 21 '22 06:10

jasonleonhard