我可以重现你的问题。有关详细信息,请参阅我的答案的结尾。
您可以通过以下方式消除差距:
- 更改
vertical-align: text-top
为vertical-align: top
.
text-top
除非您出于某种原因迫切需要(为什么?),否则这是一个简单的补救措施。
我不确定为什么在文档类型text-top
的顶部添加额外的空间。Transitional
使用此代码 ( ) 在 IE8 中进行测试XHTML 1.0 Transitional
,您描述的问题会发生:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.field {
margin: 0px;
margin-top: 2px;
background: #ccc
}
label {
display: inline-block;
width: 5em;
margin-right: 0.5em;
}
textarea {
display: inline-block;
width: 22em;
vertical-align: text-top;
}
</style>
</head>
<body>
<div class="field">
<label>Info</label><textarea cols="40" rows="4"></textarea>
</div>
</body>
</html>
如果我将第一行更改为此 ( XHTML 1.0 Strict
),则不会发生:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">