S
S
someden2015-01-21 16:18:07
css
someden, 2015-01-21 16:18:07

Why is textarea different in width from input in Webkit browsers?

For input and textarea in css, I set everything the same - paddings and margins, border, fonts, etc.
But still textarea cols='30' is wider than input size='30' in chrome, safari and opera. Everything is ok in firefox.
Why is this happening? Is there a way to fix this without changing the width?
3b0ed4156d6b47b9aea6eb139777bf06.png

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
tennalian, 2015-01-21
@tennalian

www.prntscr.com/5v72of

B
bromzh, 2015-01-21
@bromzh

Because textarea has padding. And by default, they are added to the specified size of the element. Add for textarea in css property box-sizing: border-box;
Here is another good link to check out: www.w3schools.com/css/css_boxmodel.asp

N
Nikolai Shabalin, 2015-01-21
@nikolayshabalin

I never thought about this topic, but judging by the description -
htmlbook.ru/html/input/size
htmlbook.ru/html/textarea/cols
is the same.
I was more interested in this line -
The width of the text field, which is determined by the number of characters of the monospace font .
I tried to disable the monospace font in the textarea, but to no avail.

L
Lev_Shestov, 2015-08-26
@Lev_Shestov

There is a solution to the problem on StackOverflow:
input, textarea{
font-family: Arial, sans-serif;
font-size: 100%
width: 26em; /* fallback for the next one, for browsers not recognizing ch */
width: 40ch; /* sets the width to 40 times the width of the digit “0” */
}
I don't know if this is a valid option, but it solved my problem.
link: stackoverflow.com/questions/18908018/why-do-textar...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question