2013-10-17 123 views
9

我想将一个滚动条添加到textarea,以便它始终显示,即使没有任何内容可以向下滚动时。如果没有什么东西可以向下滚动,我宁愿它可能会变灰,表示没有任何东西在下面。将滚动条添加到<textarea>

我该怎么做?

+2

使用'溢出-Y:scroll', [的jsfiddle](http://jsfiddle.net/Mr8xU/)。 – Vucko

回答

15

你需要的是overflow-y: scroll;

Demo

textarea { 
    overflow-y: scroll; 
    height: 100px; 
    resize: none; /* Remove this if you want the user to resize the textarea */ 
} 
3

你需要给你的textarea设定高度,然后设置溢出-Y

textarea 
{ 
resize: none; 
overflow-y: scroll; 
height:300px; 
} 
+1

*给你的textarea设置高度* - 没有必要:) btw同样的答案。 –

+0

@ Mr.Alien所以不需要高度? – user2370460

+1

@ user2370460不需要 –

4

尝试增加以下CSS

textarea 
{ 
    overflow-y:scroll; 
} 
1

这样

CSS

textarea { 

overflow:scroll; 
height:100px; 
} 
1

HTML:

<textarea rows="10" cols="20" id="text"></textarea> 

CSS:

#text 
{ 
    overflow-y:scroll; 
} 
2
textarea { 
    overflow-y: scroll; /* Vertical scrollbar */ 
    overflow: scroll; /* Horizontal and vertical scrollbar*/ 
}