2010-04-07 7 views
232

J'ai une zone de texte html qui est de largeur fixe, mais de hauteur variable. Je voudrais définir le débordement: faites défiler et être en mesure d'afficher une barre de défilement verticale, mais pas horizontale. Je ne suis pas capable d'utiliser le débordement: auto dû à d'autres choses spécifiques à ma situation.Masquer html barre de défilement horizontale mais pas verticale

Je sais qu'il n'y a aucun moyen d'utiliser CSS 2 pour afficher uniquement les barres de défilement verticales mais pas horizontales. Y at-il quelque chose que je peux faire avec javascript pour cacher la barre de défilement horizontale?

+2

Non, en utilisant CSS2 et 'overflow: faites défiler;' il n'y a pas moyen de montrer une barre et non l'autre. C'est inhérent à 'overflow: scroll'; javascript ne peut faire que ce que CSS permet. Cependant, je suppose que vous pouvez * utiliser * overflow: auto, vous ne savez pas comment. Pourriez-vous élaborer sur les "autres choses spécifiques à votre situation"? – tloflin

Répondre

490

Vous pouvez utiliser comme ceci css:

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

Je vois cela comme CSS3, et ça ne marche pas dans Firefox quand je le teste. Je vois aussi que c'est disponible comme une propriété d'IE seulement depuis longtemps dans la journée. –

+0

@wiliamjones - Cela fonctionne dans Firefox ... avez-vous une page d'exemple? Pourrait être une autre raison de mise en page, cela ne fonctionne pas. –

+0

@william - Voici un exemple complet de travail, test dans firefox :) http://jsfiddle.net/qpZ8k/ –

24

Utilisez CSS. C'est plus facile et plus rapide que javascript.

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

En utilisant wrap=virtual dans vos boîtes de formulaire HTML se débarrasse de la barre de défilement horizontale au bas de la boîte:

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

Voir exemple ici: http://jsbin.com/opube3/2(testé sur FF et 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; 
} 

définit la taille de défilement 200px, overflow-x masque toute barre de défilement horizontale.

14

Désactivez complètement la barre de défilement horizontale en ajoutant ce code.

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

Pour moi:

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

Bien sûr enlever les flèches

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

Exemple de travail avec extrait et un lien 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>

Questions connexes