How do I fix inconsistent Textarea bottom margin in Firefox and Chrome?
Asked Answered
Q

5

58

I'm trying to eliminate the extra bottom margin that both FF and Chrome seem to give to Textareas. Surprisingly IE seems to do it correctly. I would like to avoid using conditional includes but CSS3 tweaks are OK.

Sample Code

.red-box {
    background-color: red;
    overflow: hidden;
}
textarea {
    border: solid 1px #ddd;
    margin: 0px; /* Has no effect */
}
<div class="red-box">
    <textarea>No Margin Please!</textarea>
</div>
Qualified answered 10/8, 2010 at 22:25 Comment(1)
FWIW, I can no longer reproduce this issue on Firefox 45. It still appears on Chromium 48, though.Commonly
H
136

By default, I believe both Chrome and Firefox will set these elements as display: inline-block;. Set display: block in your styles and you should be all set.

Hendecahedron answered 10/8, 2010 at 22:31 Comment(1)
Great. But then you also have to explicitly set margin with !important. Because Chrome seems to keep the margins of the textarea to its container "fixed" when textarea uses display: block... (You may take a look at stackoverflow.com/questions/60204423 that addresses that issue.)Mahaffey
B
18

If you want to leave it inline, simply try

vertical-align: top
Brant answered 13/11, 2014 at 8:36 Comment(1)
Never knew about this! Good if you don't want to make it a block :)Consignee
I
11

Set display: block for your textarea.

Interlocutory answered 10/8, 2010 at 22:40 Comment(0)
C
3

Just bit by this in 2022 Chrome!

<textarea> has a default of vertical-align: baseline, which visually manifests as excess bottom margin.

Interestingly, none of the most popular reset/normalize stylesheets change this property. In my personal reset, I have added:

vertical-align: bottom
Coggins answered 11/8, 2022 at 20:43 Comment(0)
H
-4

Just disable resize as follow

textarea{resize: none;}

Harbird answered 19/12, 2012 at 23:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.