如何在 HTML 中定义输入文本框的大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7545302/
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
How can the size of an input text box be defined in HTML?
提问by osos
Here is an HTML input text box:
这是一个 HTML 输入文本框:
<input type="text" id="text" name="text_name" />
What are the options to define the size of the box?
定义框大小的选项有哪些?
How can this be implemented in CSS?
这如何在 CSS 中实现?
回答by Darin Dimitrov
You could set its width
:
你可以设置它的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" />
and in a separate CSS file apply the necessary styling:
并在单独的 CSS 文件中应用必要的样式:
.mytext {
width: 300px;
}
If you want to limit the number of characters that the user can type into this textbox you could use the maxlength
attribute:
如果要限制用户可以在此文本框中键入的字符数,可以使用以下maxlength
属性:
<input type="text" id="text" name="text_name" class="mytext" maxlength="25" />
回答by Fuzzy Analysis
The size
attribute works, as well
该size
属性也有效
<input size="25" type="text">
回答by Janarthanan Ramu
Try this
尝试这个
<input type="text" style="font-size:18pt;height:420px;width:200px;">
Or else
要不然
<input type="text" id="txtbox">
with the css:
使用CSS:
#txtbox
{
font-size:18pt;
height:420px;
width:200px;
}
回答by betrice mpalanzi
You can set the width in pixels via inline styling:
您可以通过内联样式设置宽度(以像素为单位):
<input type="text" name="text" style="width: 195px;">
You can also set the width with a visible character length:
您还可以使用可见字符长度设置宽度:
<input type="text" name="text" size="35">
回答by Daniel dos Santos
<input size="45" type="text" name="name">
The "size" specifies the visible width in characters of the element input.
“大小”指定元素输入的可见宽度(以字符为单位)。
You can also use the height and width from css.
您还可以使用 css 中的高度和宽度。
<input type="text" name="name" style="height:100px; width:300px;">