Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra space under textarea, differs along browsers

There`s some extra space under textarea tag. From 1 to 4 pixels in different browsers. The markup is very simple:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  <html>     <head>         <style>             body {                 margin: 0;                 padding: 0;             }             .main {                 background-color: red;             }             textarea {                 background-color: gray;                 resize: none;                 margin: 0;                 border: 0 none;                 padding: 10px;                 height: 50px;                 overflow: hidden;             }         </style>     </head>     <body>         <div class="main">             <textarea></textarea>         </div>     </body> </html> 

Here's how it is rendered in browsers:

Screenshot

Why is this happening? How to remove this extra space?

like image 205
Roman Avatar asked Aug 22 '11 08:08

Roman


People also ask

How do I get rid of extra space in textarea?

Just put your php open tag right after the textarea close tag.. Dont use line break.. And close php exactly before (as you have done).. This will erase all the whitespaces..

How do I add a space to a textarea?

Just use non-breakable spaces: &nbsp; instead of regular spaces.

How make textarea responsive width?

Try textarea {max-width:95%;} - it will always fit your display.

What are the three attributes of the textarea tag?

The main attributes of <Textarea> are: Name – Used to define name to the control. Rows – Specifies the number of rows in the text area control. Cols – Specifies the number of columns in the text area, (number of characters in a line)


2 Answers

Add vertical-align: top to textarea.

The reason for the gap is that textarea is an inline (or inline-block) element, and the gap is the space reserved for descenders in text. I don't know exactly why the gap is different between different browsers.

like image 195
thirtydot Avatar answered Oct 05 '22 23:10

thirtydot


In my case, thirtydot's answer didn't work well with the parent <div>'s bottom border.

display: block suited me nicely though.

like image 20
André Chalella Avatar answered Oct 06 '22 01:10

André Chalella