Скрыть HTML горизонтальную, но не вертикальную полосу прокрутки - PullRequest
276 голосов
/ 07 апреля 2010

У меня есть текстовая область HTML с фиксированной шириной, но переменной высоты. Я хотел бы установить overflow:scroll и иметь возможность показывать вертикальную полосу прокрутки, но не горизонтальную. Я не могу использовать overflow:auto из-за других вещей, специфичных для моей ситуации.

Я знаю, что невозможно использовать CSS2 для отображения только вертикальных, но не горизонтальных полос прокрутки. Могу ли я что-нибудь сделать с JavaScript, чтобы скрыть горизонтальную полосу прокрутки?

Ответы [ 8 ]

565 голосов
/ 07 апреля 2010

Вы можете использовать CSS так:

overflow-y: scroll;
overflow-x: hidden;
29 голосов
/ 07 апреля 2010

Используйте CSS. Это проще и быстрее, чем JavaScript.

overflow-x: hidden;
overflow-y: scroll;
21 голосов
/ 03 сентября 2014

Полностью отключите горизонтальную полосу прокрутки, добавив этот код.

body{
  overflow-x: hidden;
  overflow-y: scroll;
}
8 голосов
/ 07 апреля 2010

Использование wrap=virtual в полях формы HTML избавляет от горизонтальной полосы прокрутки внизу поля:

  <textarea name= "enquiry" rows="4" cols="30" wrap="virtual"></textarea>

См. пример здесь:http://jsbin.com/opube3/2 (протестировано на FF и IE)

2 голосов
/ 12 августа 2011
<div style="width:100px;height:100px;overflow-x:hidden;overflow-y:auto;background-color:#000000">
1 голос
/ 19 декабря 2016
selector{
 overflow-y: scroll;
 overflow-x: hidden;
}

Рабочий пример с фрагментом и ссылкой jsfiddle https://jsfiddle.net/sx8u82xp/3/

enter image description here

.container{
  height:100vh;
  overflow-y:scroll;
  overflow-x: hidden;
  background:yellow;
}
<div class="container">

<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>

<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>

<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>

<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>

</div>
1 голос
/ 25 ноября 2011
.combobox_selector ul {
    padding: 0;
    margin: 0;
    list-style: none;
    border:1px solid #CCC;
    height: 200px;
    overflow: auto;
    overflow-x: hidden;
}

устанавливает размер прокрутки 200px, overflow-x скрывает любую горизонтальную полосу прокрутки.

0 голосов
/ 11 октября 2015

Для меня:

.ui-jqgrid .ui-jqgrid-bdiv {
   position: relative;
   margin: 0;
   padding: 0;
   overflow-y: auto;  <------
   overflow-x: hidden; <-----
   text-align: left;
}

Конечно уберите стрелки

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...