html - Internet Explorer 7 为我的输入 type=image 添加了一个 3 像素的底部间隙

标签 html css internet-explorer-7

代码如下:

<!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" />
        <meta http-equiv="X-UA-Compatible" content="IE=7" />
        <title>Demo page</title>
        <style type="text/css">
            input
            {
                border: 1px solid blue;
                padding: 0px;
                margin: 0px;
                display: inline-block;
            }
            td
            {
                border: 1px solid red;
                padding: 0px;
                margin: 0px;
                height: 20px;
                max-height: 20px;
            }
        </style>
    </head>
    <body>
        <form method="get" action="">
            <table cellspacing="0" cellpadding="0" style="width: 100%">
                <tr>
                    <td>
                        <input type="image" style="width: 20px; height: 20px" src="myimg_20x20.png" alt="20x20px"/>
                    </td>
                </tr>
            </table>
        </form>
    </body>
 </html>

截图如下:

IE7 3px bottom bug

这已经在 IE8 上测试过,它出现在 IE7 模式下,以及 IE8 模式和 IE7 标准模式下。这不会出现在具有 IE8 标准的 IE8 模式中。其他浏览器(至少 Opera 和 FF)不会显示这种行为。

底部空隙是从哪里来的,为什么加了多少height: 20pxmax-height: 20px都改不掉?

最佳答案

我必须承认,我自己也在为这种事情而苦苦挣扎,但我认为这里可能发生的情况是,图像正与其容器 (td) 中出现的任何文本的基线对齐。因此,浏览器会为“y”等字符的下半部分留出空间。

您可以尝试使用 vertical-align: bottom 或设置 td 的 line-height 将 img 对齐到 td 的底部。

关于html - Internet Explorer 7 为我的输入 type=image 添加了一个 3 像素的底部间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4112582/

相关文章:

javascript - 从 Apache 网络服务器通过 Javascript 创建 Sharepoint 2013 列表项

html - 两种背景颜色(水平)

javascript - 如何禁用 IE 7 中的默认垂直滚动条?

javascript - jQuery:IE7 上的实时更改事件

html - css固定标题溢出?

javascript - 在滚动条上显示/隐藏 div

jquery - 创建触摸 slider

javascript - 使用 angularJS 自定义弹出窗口

javascript - 移植 Web 应用程序以在 IE7 中工作

html - 带按钮的背景图片