2010-04-07 27 views
232

Ho una textarea html di larghezza fissa, ma altezza variabile. Mi piacerebbe impostare l'overflow: scorrere e essere in grado di mostrare una barra di scorrimento verticale, ma non orizzontale. Non sono in grado di utilizzare l'overflow: auto a causa di altre cose specifiche della mia situazione.Hide html scrollbar orizzontale ma non verticale

So che non è possibile utilizzare CSS 2 per mostrare solo barre di scorrimento verticali ma non orizzontali. C'è qualcosa che posso fare con javascript per nascondere la barra di scorrimento orizzontale?

+2

No, utilizzando CSS2 e 'overflow: scroll;' non c'è modo per mostrare una barra e non l'altro. È inerente a "overflow: scroll"; javascript può solo fare ciò che il CSS consente. Tuttavia, suppongo che tu * possa * usare l'overflow: auto, semplicemente non sai come. Vuoi approfondire "le altre cose specifiche della tua situazione"? – tloflin

risposta

490

È possibile utilizzare i CSS in questo modo:

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

Lo vedo come CSS3 e non funziona in Firefox quando lo provo. Vedo anche che questo è disponibile come proprietà di IE solo nel lontano giorno. –

+0

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

+0

@william - Ecco un esempio completo di funzionamento, test in firefox :) http://jsfiddle.net/qpZ8k/ –

24

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

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

Utilizzando wrap=virtual nelle caselle del modulo HTML si libera della barra di scorrimento orizzontale nella parte inferiore della scatola:

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

imposta dimensioni scrolldown 200px, overflow-x nasconde qualsiasi barra di scorrimento orizzontale.

14

Disabilitare completamente la barra di scorrimento orizzontale aggiungendo questo codice.

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

Per me:

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

Naturalmente rimuovere le frecce

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

esempio Lavorare con frammento e il collegamento 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>

Problemi correlati