代码之家  ›  专栏  ›  技术社区  ›  Tower

IE7中有错误的HTML表,帮助?

  •  1
  • Tower  · 技术社区  · 15 年前

    <!DOCTYPE html>
    <html>
        <head>
            <style>
                .tl, .tr, .bl, .br, .b, .t {
                    background: #f00;
                    width: 16px;
                    height: 16px;
                }
    
                .m {
                    background: url('https://www.google.com/images/logos/ssl_logo_lg.gif') #0f0;
                }
    
                table {
                    width: 512px;
                    height: 512px;
                    border-spacing: 0px;
                    border-collapse: collapse;
                    table-layout: fixed;
                }
            </style>
        </head>
        <body>
            <table>
                <tr>
                    <td class="tl">&nbsp;</td>
                    <td class="t">&nbsp;</td>
                    <td class="tr">&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="m">test</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td class="bl">&nbsp;</td>
                    <td class="b">&nbsp;</td>
                    <td class="br">&nbsp;</td>
                </tr>
            </table>
        </body>
    </html>
    

    只要我不用IE7看就行了。出于某种原因,IE7不尊重我设置为16px的宽度和高度,而是使所有行和列采用平均大小。奇怪的是,这在怪癖模式下有效,但现在在标准模式下,怎么了?

    P、 有没有其他方法来完成类似的布局,有16x16角,16px顶部和底部,而中间适合?

    4 回复  |  直到 15 年前
        1
  •  2
  •   Sotiris Adrian J. Moreno    15 年前

    height:100%; 对于 .m

        2
  •  1
  •   Pekka    15 年前

    <td class="tl">&nbsp;</td>
    

    应该可以解决的。

        3
  •  1
  •   Å ime Vidas Zim84    15 年前

    border-spacing border-collapse IE7及以下版本不支持。尝试使用

    <table cellspacing="0" cellpadding="0">

    更新:

    我这里没有IE7和IE6,所以这只是一个猜测:尝试将.m的宽度和高度设置为auto。如果那不起作用(因为那太容易了,对吧?:)),可以手动将尺寸设置为480px(512-2*16)

        4
  •  0
  •   Michael Low    15 年前

        <style>
              table  {
                width: 512px;
                border-spacing: 0px;
                border-collapse: collapse;
                table-layout: fixed;
            }
            table .m 
            {
                background: url('https://www.google.com/images/logos/ssl_logo_lg.gif') #0f0;
                 height: 512px; 
            }
            .tl, .tr, .bl, .br, .b, .t {
                background: #f00;
                width: 16px;
                height: 16px;
    
            }
    
    
        </style>