开发者

how to remove the margin below a textarea inside a div wrapper (webkit) [duplicate]

开发者 https://www.devze.com 2023-01-22 03:43 出处:网络
This question already has answers here: How do I fix inconsistent Textarea bottom margin in Firefox and Chrome?
This question already has answers here: How do I fix inconsistent Textarea bottom margin in Firefox and Chrome? (5 answers) Closed 6 years ago.
 <!DOCTYPE html>
 <html> 
 <head>
 </head>
 <body>
      <div style="background-color:#f09;">
           <textarea></textarea>
      </div>
 </body>开发者_StackOverflow;
 </html>

Result in Chrome:

removed dead ImageShack link

Result in FF:

removed dead ImageShack link


Try display:block on the textarea:

 <!DOCTYPE html>
 <html> 
 <head>
      <style type="text/css">
           textarea {display:block;}
      </style>
 </head>
 <body>
      <div style="background-color:#f09;">
           <textarea></textarea>
      </div>
 </body>
 </html>

The issue is that the textarea is inline and it is using the text height to add a bit of extra padding. You can also specify:

 <!DOCTYPE html>
 <html> 
 <head>
 </head>
 <body>
      <div style="background-color:#f09;line-height:0px;font-size:1px;">
           <textarea></textarea>
      </div>
 </body>
 </html>

Another option which is helpful if you want to keep the textarea inline and don't want to mess with the parent block's font properties (I suggest this over the previous method with line-height):

 <!DOCTYPE html>
 <html> 
 <head>
      <style type="text/css">
           textarea {vertical-align:middle;}
      </style>
 </head>
 <body>
      <div style="background-color:#f09;">
           <textarea></textarea>
      </div>
 </body>
 </html>

Finally, if you're really worried about consistency between browsers keep in mind margins and other things like that can be defined with different defaults in different browsers. Utilizing something like YUI-Reset can help bring all new browsers to a consistent standard from which you can build.


Setting the display mode to block did the trick for me. Just to clarify, here is the declaration that you need to add to your stylesheet. I would recommend adding it to your reset or normalize stylesheet, in the first place.

textarea {
    display:block
}


I usually have a "first line" in every global.css file I make. saying:

<style>    
html,body,p,h1,h2,h3,h4,h5,h6,img,table,td,th 
{
   margin:0;padding:0;border:none;
   font-familiy:"my sites default font";font-size:10px;
}
</style>

After this, I feel that I have full control of the browsers behaviour, when testing on 5 different platforms: Chrome, Firefox, Safari, Opera and ... doh... Microsoft Internet Extracrap..

Then you can easily do something similar for < input > and < textarea > too. if the first line does too much, then just make a second line for the "special cases" alone.

<style>
textarea {margin:0; padding:0; border:none; display:block;}
</style>

Remember that CSS inherits, so you can have multiple declarations of different classes.

Does this remove your problem?

0

精彩评论

暂无评论...
验证码 换一张
取 消