2010-04-07 98 views
232

我有一個固定寬度但高度可變的html textarea。我想設置溢出:滾動,並能夠顯示垂直滾動條,但不是水平滾動條。由於其他情況,我無法使用overflow:auto。隱藏html橫向但不是垂直滾動條

我知道有沒有辦法使用CSS 2來顯示只有垂直滾動條而不是水平滾動條。有什麼我可以用JavaScript來隱藏水平滾動條?

+2

沒有使用CSS2和'溢出:滾動;'沒有辦法顯示一個欄,而不是其他。它是'overflow:scroll'中固有的; JavaScript只能做CSS允許的。但是,我的猜測是,你*可以*使用溢出:汽車,你只是不知道如何。你會詳細說明「與你情況相關的其他事情」嗎? – tloflin 2010-04-07 17:06:30

回答

490

您可以使用CSS這樣的:

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

我看到,作爲CSS3,並且它在Firefox中不起作用,當我測試它時。我還看到,這種方式僅在今天的IE瀏覽器中可用。 – 2010-04-07 17:03:31

+0

@wiliamjones - 這在Firefox中工作...你有一個例子頁面?可能是其他佈局原因,它不起作用。 – 2010-04-07 17:04:34

+0

@william - 這是一個完整的工作示例,在Firefox中測試:) http://jsfiddle.net/qpZ8k/ – 2010-04-07 17:16:21

24

使用CSS。它比JavaScript更簡單快捷。

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

使用HTML表單盒wrap=virtual被在盒子的底部去掉水平滾動條:

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

例如這裏:http://jsbin.com/opube3/2(測試FF和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; 
} 

設置200px scrolldown大小,overflow-x隱藏任何水平滾動條。

14

通過添加此代碼完全禁用水平滾動條。

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

對於我來說:

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

當然取出箭頭

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

工作與片段和鏈接的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>