Ocultar barra de rolagem horizontal, mas não vertical, em html

279

Eu tenho uma área de texto HTML que é de largura fixa, mas altura variável. Gostaria de definir overflow:scrolle poder mostrar uma barra de rolagem vertical, mas não a horizontal. Não consigo usar overflow:autodevido a outras coisas específicas da minha situação.

Eu sei que não há como usar CSS2 para mostrar apenas barras de rolagem verticais, mas não horizontais. Existe algo que eu possa fazer com JavaScript para ocultar a barra de rolagem horizontal?

William Jones
fonte
3
Não, usando CSS2 e overflow:scroll;não há como mostrar uma barra e não a outra. É inerente a overflow:scroll; javascript pode fazer apenas o que o CSS permite. No entanto, meu palpite é que você pode usar overflow: auto, você simplesmente não sabe como. Você elaboraria as "outras coisas específicas da sua situação"?
tloflin

Respostas:

575

Você pode usar css assim:

overflow-y: scroll;
overflow-x: hidden;
Nick Craver
fonte
2
Estou vendo isso como CSS3, e ele não funciona no Firefox quando testá-lo. Também vejo que isso está disponível como uma propriedade somente do IE desde o início do dia.
William Jones
@wiliamjones - Isso funciona no firefox ... você tem uma página de exemplo? Pode haver outro motivo para o layout não estar funcionando.
Nick Craver
@william - Aqui está um exemplo completo dele funcionando, teste no firefox :) jsfiddle.net/qpZ8k
Nick Craver
Você está certo, ele funciona com o Firefox, é a biblioteca javascript Prototype que não é compatível com esse atributo, o que foi fácil de contornar. Essa propriedade geralmente é confiável entre navegadores?
William Jones
@williamjones - Sim, geralmente é o caso com essas coisas, os navegadores o implementam e, em seguida, é um padrão posteriormente.
Nick Craver
30

Use CSS. É mais fácil e rápido que o javascript.

overflow-x: hidden;
overflow-y: scroll;
Kevin
fonte
22

Desative completamente a barra de rolagem horizontal adicionando este código.

body{
  overflow-x: hidden;
  overflow-y: scroll;
}
rpalzona
fonte
9

O uso wrap=virtualnas caixas de formulário HTML se livra da barra de rolagem horizontal na parte inferior da caixa:

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

Veja o exemplo aqui: http://jsbin.com/opube3/2 (Testado no FF e IE)

Jitendra Vyas
fonte
2
<div style="width:100px;height:100px;overflow-x:hidden;overflow-y:auto;background-color:#000000">
Tirupati Balan
fonte
2
selector{
 overflow-y: scroll;
 overflow-x: hidden;
}

Exemplo de trabalho com link de snippet e jsfiddle https://jsfiddle.net/sx8u82xp/3/

insira a descrição da imagem aqui

.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>

Santosh Khalse
fonte
1
.combobox_selector ul {
    padding: 0;
    margin: 0;
    list-style: none;
    border:1px solid #CCC;
    height: 200px;
    overflow: auto;
    overflow-x: hidden;
}

define o tamanho de rolagem de 200px, overflow-xoculta qualquer barra de rolagem horizontal.

maultrommel
fonte
0

Para mim:

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

Claro que remova as setas

Onyximo
fonte