user225269
user225269

Reputation: 10913

How do I set the size of an HTML text box?

How do I set the size of an HTML text box?

Upvotes: 117

Views: 657477

Answers (10)

Johnny Vikrant
Johnny Vikrant

Reputation: 29

If you don't want to use the class method you can use parent-child method to make changes in the text box.

For eg. I've made a form in my form div.

HTML Code:

<div class="form">
    <textarea name="message" rows="10" cols="30" >Describe your project in detail.</textarea>
</div>

Now CSS code will be like:

.form textarea {
    height: 220px;
    width: 342px;
}

Problem solved.

Upvotes: 3

Ilya Degtyarenko
Ilya Degtyarenko

Reputation: 1569

You can make the dependent input width versus container width.

.container {
   width: 360px;
}

.container input {
   width: 100%;
}

Upvotes: 2

R Keene
R Keene

Reputation: 71

Lookout! The width attribute is clipped by the max-width attribute. So I used....

    <form method="post" style="width:1200px">
    <h4 style="width:1200px">URI <input type="text" name="srcURI" id="srcURI" value="@m.SrcURI" style="width:600px;max-width:600px"/></h4>

Upvotes: 2

joym8
joym8

Reputation: 4212

This works for me in IE 10 and FF 23

<input type="text" size="100" />

Upvotes: 6

Lightsaber
Lightsaber

Reputation: 125

Your textbox code:

<input type="text" class="textboxclass" />

Your CSS code:

input[type="text"] {
height: 10px;
width: 80px;
}

or

.textboxclass {
height: 10px;
width: 80px;
}

So, first you select your element with attributes (look at first example) or classes(look last example). Later, you assign height and width values to your element.

Upvotes: 7

Matchu
Matchu

Reputation: 85794

Elements can be sized with the height and width attributes.

Upvotes: 1

Erol Balci
Erol Balci

Reputation: 33

Try:

input[type="text"]{
padding:10px 0;}

This is way it remains independent of what textsize has been set for the textbox. You are increasing the height using padding instead

Upvotes: 1

Rowno
Rowno

Reputation: 3394

Just use:

textarea {
    width: 200px;
}

or

input[type="text"] {
    width: 200px;
}

Depending on what you mean by 'textbox'.

Upvotes: 137

tcao
tcao

Reputation: 121

input[type="text"]
{
    width:200px
}

Upvotes: 12

Dan Herbert
Dan Herbert

Reputation: 103407

Your markup:

<input type="text" class="resizedTextbox" />

The CSS:

.resizedTextbox {width: 100px; height: 20px}

Keep in mind that text box size is a "victim" of the W3C box model. What I mean by victim is that the height and width of a text box is the sum of the height/width properties assigned above, in addition to the padding height/width, and the border width. For this reason, your text boxes will be slightly different sizes in different browsers depending on the default padding in different browsers. Although different browsers tend to define different padding to text boxes, most reset style sheets don't tend to include <input /> tags in their reset sheets, so this is something to keep in mind.

You can standardize this by defining your own padding. Here is your CSS with specified padding, so the text box looks the same in all browsers:

.resizedTextbox {width: 100px; height: 20px; padding: 1px}

I added 1 pixel padding because some browsers tend to make the text box look too crammed if the padding is 0px. Depending on your design, you may want to add even more padding, but it is highly recommend you define the padding yourself, otherwise you'll be leaving it up to different browsers to decide for themselves. For even more consistency across browsers, you should also define the border yourself.

Upvotes: 41

Related Questions