2010-04-07 28 views
232

Tengo un área de texto html que es de ancho fijo, pero altura variable. Me gustaría establecer el desbordamiento: desplácese y ser capaz de mostrar una barra de desplazamiento vertical, pero no una horizontal. No puedo utilizar el desbordamiento: automático debido a otras cosas específicas de mi situación.Ocultar barra de desplazamiento horizontal html pero no vertical

Sé que no hay forma de usar CSS 2 para mostrar solo barras de desplazamiento verticales pero no horizontales. ¿Hay algo que pueda hacer con javascript para ocultar la barra de desplazamiento horizontal?

+2

No, utilizando CSS2 y 'desbordamiento: desplazarse;' no hay manera de mostrar una barra y no al contrario. Es inherente a 'overflow: scroll'; javascript solo puede hacer lo que permite CSS. Sin embargo, supongo que usted * puede * usar desbordamiento: automático, simplemente no sabe cómo. ¿Podrías profundizar en las "otras cosas específicas de tu situación"? – tloflin

Respuesta

490

Puede utilizar css así:

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

Lo estoy viendo como CSS3, y no funciona en Firefox cuando lo pruebo. También veo que esto está disponible como propiedad exclusiva de IE desde hace mucho tiempo. –

+0

@wiliamjones - Esto funciona en Firefox ... ¿tienes una página de ejemplo? Podría ser algún otro motivo de diseño que no funciona. –

+0

@william - Aquí hay un ejemplo completo de cómo funciona, prueba en firefox :) http://jsfiddle.net/qpZ8k/ –

24

uso de CSS. Es más fácil y más rápido que javascript.

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

Usando wrap=virtual en sus cuadros de formulario HTML se deshace de la barra de desplazamiento horizontal en la parte inferior de la caja:

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

Ver ejemplo aquí: http://jsbin.com/opube3/2(probado en FF y el 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; 
} 

establece 200px scrolldown size, overflow-x oculta cualquier barra de desplazamiento horizontal.

14

Deshabilite la barra de desplazamiento horizontal por completo agregando este código.

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

Para mí:

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

Por supuesto quitar las flechas

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

Ejemplo de trabajo con el fragmento y enlace 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>

Cuestiones relacionadas