textarea下的额外空间,因浏览器而异 [英] Extra space under textarea, differs along browsers
本文介绍了textarea下的额外空间,因浏览器而异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在textarea标签下有一些额外的空间。不同浏览器中的1到4个像素。标记非常简单:
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:
为什么会发生这种情况?如何清除此额外空间?
Why is this happening? How to remove this extra space?
推荐答案
添加 vertical-align:top
到 textarea
。
差距的原因是 textarea
是 inline
(或 inline-block
)元素,间隙是为下降。我不知道为什么不同的浏览器之间的差距是不同的。
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.
这篇关于textarea下的额外空间,因浏览器而异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文