Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input and textarea appear different width when are set to same width?

Tags:

html

css

When I set the width of an input and a text area to 94% they appear to be slightly different in width. This is something I have seen many times on many sites.

Can anyone explain why a textarea is not as wide as an input when set to the same % width?

input, textarea {
    width: 94%;
}
like image 237
dibs Avatar asked Jun 12 '12 00:06

dibs


People also ask

How do I fix the width of my textarea?

To prevent a text field from being resized, you can use the CSS resize property with its "none" value. After it you can use the height and width properties to define a fixed height and width for your <textarea> element.

Does textarea have a value attribute?

<textarea> does not support the value attribute.

Is textarea an input?

Definition and Usage. The <textarea> tag defines a multi-line text input control. The <textarea> element is often used in a form, to collect user inputs like comments or reviews. A text area can hold an unlimited number of characters, and the text renders in a fixed-width font (usually Courier).


2 Answers

  1. Don't forget the box model includes borders, padding, and margins. They all affect the actual physical width of an element in the page.
  2. Unless you use a CSS reset you're at the mercy of the default browser stylesheets which set different borders, padding, and margins for each element.
like image 72
John Conde Avatar answered Oct 02 '22 03:10

John Conde


With CSS3 you can also use:

-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box;    /* Firefox, other Gecko */
box-sizing: border-box;         /* Opera/IE 8+ */
like image 39
Ricardo Marimon Avatar answered Oct 02 '22 05:10

Ricardo Marimon