HTMLを水平に非表示にし、垂直にスクロールしない


279

幅は固定ですが高さは可変のHTMLテキストエリアがあります。overflow:scroll垂直スクロールバーを設定して表示できるようにしたいが、水平スクロールバーは表示したくない。overflow:auto他の事情により使用できません。

CSS2を使用して、垂直スクロールバーのみを表示し、水平スクロールバーは表示しない方法はないことを知っています。水平スクロールバーを非表示にするためにJavaScriptでできることはありますか?


3
いいえ、CSS2を使用していoverflow:scroll;ます。一方のバーを表示し、もう一方のバーを表示する方法はありません。それはに固有のものoverflow:scrollです。JavaScriptは、CSSが許可するもののみを実行できます。しかし、私の推測では、overflow:autoを使用できると思います。「あなたの状況に固有のその他のこと」について詳しく教えてください。
tloflin 2010

回答:


575

次のようにcssを使用できます。

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

2
私はそれをCSS3として見ています、そしてそれをテストしたとき、それはFirefoxで機能しません。また、これは昔からIEのみのプロパティとして利用できることもわかりました。
ウィリアムジョーンズ

@wiliamjones-これはFirefoxで動作します...サンプルページはありますか?それが機能していない理由として、他のレイアウトが考えられます。
Nick Craver

@william-これが機能する完全な例です。Firefox
Nick Craver

そうです、Firefoxで動作します。これは、この属性と互換性のないPrototype JavaScriptライブラリであり、簡単に回避できました。このプロパティは一般的にブラウザ間で信頼できますか?
ウィリアムジョーンズ

@williamjones-うん、そういうことは普通そうだ。ブラウザがそれを実装して、あとで後から考えると標準になる。
Nick Craver

30

CSSを使用します。JavaScriptよりも簡単で高速です。

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

22

このコードを追加して、水平スクロールバーを完全に無効にします。

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

9

wrap=virtualHTMLフォームボックスで使用すると、ボックスの下部にある水平スクロールバーが削除されます。

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

ここの例を参照してください:http : //jsbin.com/opube3/2 (FFおよびIEでテスト済み)



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

スニペットとjsfiddleリンクを使用した作業例https://jsfiddle.net/sx8u82xp/3/

ここに画像の説明を入力してください

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

200pxのスクロールダウンサイズを設定しoverflow-x、水平スクロールバーを非表示にします。


0

私のために:

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

もちろん矢印を削除します

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.