简体   繁体   English

如何在左侧放置 div 滚动条?

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

Is it possible to specify a position (left or right hand side) for the placement of a vertical scrollbar on a div?是否可以为在 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?有没有办法将该滚动条放在可滚动区域的左侧?

You could try direction:rtl;你可以试试direction:rtl; in your css.在你的 CSS 中。 Then reset the text direction in the inner div然后重置内部div中的文本方向

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

#scroll div{
    direction:ltr;
}

Untested.未经测试。

 .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工作示例: JSFiddle

or或者

Cut and paste solution that works for all major browsers (Even Safari)适用于所有主要浏览器(甚至 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.可选地将class="item_direction添加到每个项目以更改文本流回的方向,同时保留容器方向。

Kind of an old question, but I thought I should throw in a method which wasn't widely available when this question was asked.有点老问题,但我认为我应该提出一种在提出这个问题时尚未广泛使用的方法。

You can reverse the side of the scrollbar in modern browsers using transform: scaleX(-1) on a parent <div> , then apply the same transform to reverse a child, "sleeve" element.您可以在现代浏览器中使用transform: scaleX(-1)在父<div>上反转滚动条的一侧,然后应用相同的转换来反转子“sleeve”元素。

HTML HTML

<div class="parent">
  <div class="sleeve">
    <!-- content -->
  </div>
</div>

CSS CSS

.parent {
  overflow: auto;
  transform: scaleX(-1); //Reflects the parent horizontally
}

.sleeve {
  transform: scaleX(-1); //Flips the child back to normal
}

Note: You may need to use an -ms-transform or -webkit-transform prefix for browsers as old as IE 9. Check CanIUse and click "show all" to see older browser requirements.注意:对于 IE 9 以前的浏览器,您可能需要使用-ms-transform-webkit-transform前缀。选中CanIUse并单击“显示全部”以查看较旧的浏览器要求。

I have the same problem.我也有同样的问题。 but when i add direction: rtl;但是当我添加direction: rtl; in tabs and accordion combo but it crashes my structure.在标签和手风琴组合中,但它使我的结构崩溃。

The way to do it is add div with direction: rtl;这样做的方法是添加带有direction: rtl; as parent element, and for child div set direction: ltr;作为父元素,并为子div设置direction: ltr; . .

I use this first https://api.jquery.com/wrap/我首先使用这个https://api.jquery.com/wrap/

$( ".your selector of child element" ).wrap( "<div class='scroll'></div>" );

then just simply work with css :)然后只需简单地使用 css :)

In children div add to css在儿童 div 添加到 css

 .your_class {
            direction: ltr;    
        }

And to parent div added by jQuery with class .scroll并添加到 jQuery 使用类 .scroll 添加的父 div

.scroll {
            unicode-bidi:bidi-override;
            direction: rtl;
            overflow: scroll;
            overflow-x: hidden!important;
        }

Works prefect for me适合我

http://jsfiddle.net/jw3jsz08/1/ http://jsfiddle.net/jw3jsz08/1/

No, you can't change scrollbars placement without any additional issues.不,您不能在没有任何其他问题的情况下更改滚动条的位置。

You can change text-direction to right-to-left ( rtl ), but it also change text position inside block.您可以将文本方向更改为从右到左( rtl ),但它也会更改块内的文本位置。

This code can helps you, but I not sure it works in all browsers and OS.此代码可以帮助您,但我不确定它是否适用于所有浏览器和操作系统。

<element style="direction: rtl; text-align: left;" />

Here is what I have done to make the right scroll bar work.这是我为使正确的滚动条工作所做的工作。 The only thing needed to be considered is when using 'direction: rtl' and whole table also need to be changed.唯一需要考虑的是在使用“direction: rtl”时,整个表也需要更改。 Hopefully this gives you an idea how to do it.希望这能让你知道如何去做。

Example:例子:

<table dir='rtl'><tr><td>Display Last</td><td>Display Second</td><td>Display First</td></table>

Check this: JSFiddle检查这个: JSFiddle

There is a dedicated npm package for it.它有一个专用的npm包。 css-scrollbar-side css-滚动条侧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM