将滚动条添加到<textarea> </textarea>

时间:2013-10-17 07:43:49

标签: html css scroll textarea

我想在textarea中添加一个滚动条,以便它始终显示,即使没有任何内容可以向下滚动。如果没有任何东西可以向下滚动,我宁愿它是否会变灰,表明下面没有任何内容。

我该怎么做?

6 个答案:

答案 0 :(得分:22)

您需要的是overflow-y: scroll;

Demo

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

答案 1 :(得分:5)

尝试添加以下CSS

textarea
{
    overflow-y:scroll;
}

答案 2 :(得分:4)

您需要为textarea设置一个设定的高度,然后设置overflow-y

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

答案 3 :(得分:2)

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

答案 4 :(得分:1)

像这样

<强> CSS

textarea {

overflow:scroll;
height:100px;
}

答案 5 :(得分:1)

HTML:

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

CSS:

#text
{
    overflow-y:scroll;
}