代码之家  ›  专栏  ›  技术社区  ›  Vilx-

Internet explorer 7在“我的输入类型=图像”中添加3像素的底部间隙

  •  2
  • Vilx-  · 技术社区  · 15 年前

    代码如下:

    <!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

    底部的缺口是从哪里来的,为什么我不能消除它,不管有多少 height: 20px max-height: 20px 我补充说?

    6 回复  |  直到 15 年前
        1
  •  4
  •   user123444555621    15 年前

    您应该尝试删除空白,如下所示:

            <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>
    

    我知道很难看。

        2
  •  5
  •   Steve    15 年前

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

    vertical-align: bottom 或设置 line-height td的。

        3
  •  1
  •   Michael M.    13 年前

    酒神是正确的关于“4像素边缘”的行为,这是由显示图像作为内联。但是Internet Explorer不一定会将它们识别为图像,因此会在任何图像的底部添加4像素的边距。

    将“display:block;”的内联样式添加到表中的每个图像。这将阻止Internet Explorer像内联元素时那样添加4个像素的空白。

    我在InternetExplorer7、8和9中对此进行了测试。当前版本的Firefox、Chrome、Safari和Opera都能很好地处理这种风格。

        4
  •  0
  •   Zubair1    15 年前

    @维尔克斯- 您是否尝试过实现条件标记以仅覆盖IE7的css行为?

    例如:

    <!--[if IE 7]>
    <style type="text/css">
            form {margin:0px;}
            input {margin:0px;}
    </style>
    <![endif]-->
    

    但我真正想建议的是,您可以尝试在页面上使用类似这样的CSS重置: http://meyerweb.com/eric/tools/css/reset/

        5
  •  0
  •   animuson    14 年前

    例子:

    <tr>                     
    <td>                         
    <input type="image" style="width: 20px; height: 20px" src="myimg_20x20.png" alt="20x20px"/>                     
    </td>                 
    </tr>
    

    新的无空格:

    <tr><td><input type="image" style="width: 20px; height: 20px" src="myimg_20x20.png" alt="20x20px"/></td></tr>
    
        6
  •  0
  •   Dionysios Arvanitis    13 年前

    我认为这被称为“IE4像素边距”错误,是由display:inline块引起的;最好的解决方案是为IE8及其以下添加一个边距底部:-4px\9属性。