Html 光标在文本区域框的中间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9070924/
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-28 22:10:33  来源:igfitidea点击:

Cursor in the middle of a textarea box?

htmlcss

提问by Ray

In a very simple HTML form I've created, I've asked the user to provide additional details and have coded this section as:

在我创建的一个非常简单的 HTML 表单中,我要求用户提供其他详细信息并将此部分编码为:

<textarea rows="1" cols="50" wrap="physical" name="comments">

</textarea>

Any idea why the cursor starts off at the middle of this box? Well, it's not directly at the middle, but it's definitely not at the start (top left) corner of the box. I see a lot of solutions here and they all require Javascript to correct this. Is there a way to do this with just html?

知道为什么光标从这个框的中间开始吗?嗯,它不是直接在中间,但绝对不是在盒子的开始(左上角)。我在这里看到了很多解决方案,它们都需要 Javascript 来纠正这个问题。有没有办法只用html来做到这一点?

回答by nachito

What happens when you change it to:

将其更改为:

<textarea rows="1" cols="50" wrap="physical" name="comments"></textarea>

I think it's not starting at the beginning because you've got whitespace inside the tag.

我认为它不是从一开始就开始,因为标签内有空格。

回答by Rokin

The reason that this happens is because you have white space in between the <textarea>tag. Try this

发生这种情况的原因是<textarea>标签之间有空格。尝试这个

<textarea rows="1" cols="50" wrap="physical" name="comments"></textarea>

回答by Zeewon Maharjan

That generally happens when we enter a space between two opening and closing "textarea" tag for readibility.

当我们在两个开始和结束的“textarea”标签之间输入一个空格以提高可读性时,通常会发生这种情况。

i.e your opening <textarea>tag and Closing </textarea>tags are on different lines or there are some white spaces between them.

即你的开始<textarea>标签和结束</textarea>标签在不同的行上,或者它们之间有一些空白。

回答by Gus

That does sound strange. Have you looked in firebug to see what CSS effects it? The only thing that comes to mind is that it's under the influence of text-align: center

这听起来很奇怪。你有没有在 firebug 中查看过什么 CSS 效果呢?唯一想到的是它受到了text-align: center