How can the size of an input text box be defined i

2019-03-08 18:00发布

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?

How can this be implemented in CSS?

标签: html css input
5条回答
贪生不怕死
2楼-- · 2019-03-08 18:14
<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.

<input type="text" name="name" style="height:100px; width:300px;">
查看更多
趁早两清
3楼-- · 2019-03-08 18:25

Try this

<input type="text" style="font-size:18pt;height:420px;width:200px;">

Or else

 <input type="text" id="txtbox">

with the css:

 #txtbox
    {
     font-size:18pt;
     height:420px;
     width:200px;
    }
查看更多
相关推荐>>
4楼-- · 2019-03-08 18:31

The size attribute works, as well:

<input size="25" type="text" />
查看更多
孤傲高冷的网名
5楼-- · 2019-03-08 18:31

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" />

查看更多
Juvenile、少年°
6楼-- · 2019-03-08 18:32

You could set its 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:

.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:

<input type="text" id="text" name="text_name" class="mytext" maxlength="25" />
查看更多
登录 后发表回答