Ukryj poziomy pasek przewijania HTML, ale nie pionowy


279

Mam obszar tekstowy HTML o stałej szerokości, ale o zmiennej wysokości. Chciałbym ustawić overflow:scrolli móc wyświetlić pionowy pasek przewijania, ale nie poziomy. Nie mogę korzystać overflow:autoz innych rzeczy specyficznych dla mojej sytuacji.

Wiem, że nie ma możliwości używania CSS2 do wyświetlania tylko pionowych, ale nie poziomych pasków przewijania. Czy mogę coś zrobić z JavaScript, aby ukryć poziomy pasek przewijania?


3
Nie, używając CSS2 i overflow:scroll;nie ma sposobu, aby pokazać jeden pasek, a nie drugi. Jest to nieodłączne overflow:scroll; javascript może robić tylko to, na co pozwala CSS. Jednak domyślam się, że możesz użyć przelewu: auto, po prostu nie wiesz jak. Czy rozwinąłbyś „inne rzeczy specyficzne dla twojej sytuacji”?
tloflin,

Odpowiedzi:


575

Możesz użyć css w następujący sposób:

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

2
Widzę to jako CSS3 i nie działa w Firefoksie, kiedy go testuję. Widzę też, że jest dostępna jako właściwość tylko dla IE z dawnych czasów.
William Jones,

@wiliamjones - To działa w Firefoksie ... czy masz przykładową stronę? Może to być inny powód, dla którego układ nie działa.
Nick Craver

@william - Oto kompletny przykład jego działania, przetestowania w firefoxie
Nick Craver

Masz rację, działa z Firefoksem, to Prototypowa biblioteka javascript, która nie jest kompatybilna z tym atrybutem, co było dość łatwe do obejścia. Czy ta właściwość jest ogólnie niezawodna we wszystkich przeglądarkach?
William Jones,

@williamjones - Tak, zwykle dzieje się tak w przypadku tych rzeczy, przeglądarki go implementują, potem jest to standard później.
Nick Craver

30

Użyj CSS. To łatwiejsze i szybsze niż javascript.

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

22

Całkowicie wyłącz poziomy pasek przewijania, dodając ten kod.

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

9

Użycie wrap=virtualw polach formularza HTML pozbywa się poziomego paska przewijania u dołu pola:

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

Zobacz przykład tutaj: http://jsbin.com/opube3/2 (Testowane na FF i 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;
}

Przykład działania z fragmentem kodu i linkiem jsfiddle https://jsfiddle.net/sx8u82xp/3/

wprowadź opis zdjęcia tutaj

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

ustawia rozmiar overflow-xprzewijania 200 pikseli, ukrywa dowolny poziomy pasek przewijania.


0

Dla mnie:

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

Oczywiście usuń strzały

Korzystając z naszej strony potwierdzasz, że przeczytałeś(-aś) i rozumiesz nasze zasady używania plików cookie i zasady ochrony prywatności.
Licensed under cc by-sa 3.0 with attribution required.