Add a scrollbar to a <textarea> [duplicate]

2020-08-09 11:41发布

I would like to add a scrollbar to a textarea, so that it always appears, even when there is nothing to scroll down to. If there is nothing for it to scroll down to, I would prefer if it could be greyed out, indicating that there is nothing below.

How would I do this?

6条回答
等我变得足够好
2楼-- · 2020-08-09 11:54

like this

css

textarea {

overflow:scroll;
height:100px;
}
查看更多
手持菜刀,她持情操
3楼-- · 2020-08-09 12:00

What you need is overflow-y: scroll;

Demo

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

查看更多
Summer. ? 凉城
4楼-- · 2020-08-09 12:04

HTML:

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

CSS:

#text
{
    overflow-y:scroll;
}
查看更多
叼着烟拽天下
5楼-- · 2020-08-09 12:08
textarea {
    overflow-y: scroll; /* Vertical scrollbar */
    overflow: scroll; /* Horizontal and vertical scrollbar*/
}
查看更多
放我归山
6楼-- · 2020-08-09 12:14

You will need to give your textarea a set height and then set overflow-y

textarea
{
resize: none;
overflow-y: scroll;
height:300px;
}
查看更多
Rolldiameter
7楼-- · 2020-08-09 12:20

Try adding below CSS

textarea
{
    overflow-y:scroll;
}
查看更多
登录 后发表回答