Nascondi barra di scorrimento HTML orizzontale ma non verticale


279

Ho un'area di testo HTML di larghezza fissa, ma altezza variabile. Vorrei impostare overflow:scrolled essere in grado di mostrare una barra di scorrimento verticale, ma non orizzontale. Non sono in grado di utilizzare a overflow:autocausa di altre cose specifiche della mia situazione.

So che non è possibile usare CSS2 per mostrare solo barre di scorrimento verticali ma non orizzontali. C'è qualcosa che posso fare con JavaScript per nascondere la barra di scorrimento orizzontale?


3
No, usando CSS2 e overflow:scroll;non c'è modo di mostrare una barra e non l'altra. È inerente a overflow:scroll; javascript può fare solo ciò che CSS consente. Tuttavia, la mia ipotesi è che puoi usare l'overflow: auto, semplicemente non sai come. Vuoi approfondire le "altre cose specifiche della tua situazione"?
tloflin,

Risposte:


575

Puoi usare CSS in questo modo:

overflow-y: scroll;
overflow-x: hidden;

2
Lo vedo come CSS3, e non funziona in Firefox quando lo collaudo. Vedo anche che questo è disponibile come proprietà IE solo nel passato.
William Jones,

@wiliamjones - Funziona in Firefox ... hai una pagina di esempio? Potrebbe essere un altro motivo di layout che non funziona.
Nick Craver

@william - Ecco un esempio completo del suo funzionamento, test in firefox :) jsfiddle.net/qpZ8k
Nick Craver

Hai ragione, funziona con Firefox, è la libreria javascript Prototype che non è compatibile con questo attributo, che è stato abbastanza facile da aggirare. Questa proprietà è generalmente affidabile su tutti i browser?
William Jones,

@williamjones - Sì, di solito è il caso di queste cose, i browser lo implementano, quindi è uno standard in seguito come ripensamento.
Nick Craver

30

Usa CSS. È più facile e veloce di JavaScript.

overflow-x: hidden;
overflow-y: scroll;

22

Disabilita completamente la barra di scorrimento orizzontale aggiungendo questo codice.

body{
  overflow-x: hidden;
  overflow-y: scroll;
}

9

L'utilizzo wrap=virtualnelle caselle del modulo HTML elimina la barra di scorrimento orizzontale nella parte inferiore della casella:

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

Vedi esempio qui: http://jsbin.com/opube3/2 (testato su FF e IE)


2
<div style="width:100px;height:100px;overflow-x:hidden;overflow-y:auto;background-color:#000000">

2
selector{
 overflow-y: scroll;
 overflow-x: hidden;
}

Esempio di lavoro con snippet e collegamento jsfiddle https://jsfiddle.net/sx8u82xp/3/

inserisci qui la descrizione dell'immagine

.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
.combobox_selector ul {
    padding: 0;
    margin: 0;
    list-style: none;
    border:1px solid #CCC;
    height: 200px;
    overflow: auto;
    overflow-x: hidden;
}

imposta la dimensione di scorrimento di 200 px, overflow-xnasconde qualsiasi barra di scorrimento orizzontale.


0

Per me:

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

Naturalmente rimuovi le frecce

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.