Html 向 <textarea> 添加滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19420923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:32:01  来源:igfitidea点击:

Add a scrollbar to a <textarea>

htmlcssscrolltextarea

提问by user2370460

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.

我想向 textarea 添加一个滚动条,以便它始终出现,即使没有向下滚动的内容。如果它没有向下滚动到的任何内容,我希望它可以变灰,表示下面没有任何内容。

How would I do this?

我该怎么做?

回答by Mr. Alien

What you need is overflow-y: scroll;

你需要的是 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>

回答by Kishori

Try adding below CSS

尝试在下面添加 CSS

textarea
{
    overflow-y:scroll;
}

回答by Dale

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

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

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

回答by Don

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

回答by Falguni Panchal

like this

像这样

css

css

textarea {

overflow:scroll;
height:100px;
}

回答by Pbk1303

HTML:

HTML:

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

CSS:

CSS:

#text
{
    overflow-y:scroll;
}