如何在 HTML 中定义输入文本框的大小? [英] How can the size of an input text box be defined in HTML?
本文介绍了如何在 HTML 中定义输入文本框的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个 HTML 输入文本框:
Here is an HTML input text box:
<input type="text" id="text" name="text_name" />
定义框大小的选项有哪些?
What are the options to define the size of the box?
如何在 CSS 中实现?
How can this be implemented in CSS?
推荐答案
你可以设置它的width
:
<input type="text" id="text" name="text_name" style="width: 300px;" />
甚至更好地定义一个类:
or even better define a class:
<input type="text" id="text" name="text_name" class="mytext" />
并在单独的 CSS 文件中应用必要的样式:
and in a separate CSS file apply the necessary styling:
.mytext {
width: 300px;
}
如果您想限制用户可以在此文本框中键入的字符数,您可以使用 maxlength
属性:
If you want to limit the number of characters that the user can type into this textbox you could use the maxlength
attribute:
<input type="text" id="text" name="text_name" class="mytext" maxlength="25" />
这篇关于如何在 HTML 中定义输入文本框的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文