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

使用<table>父元素以百分比定义宽度和高度时,不会渲染图像

  •  3
  • Brian  · 技术社区  · 16 年前

    我正在尝试按百分比缩小图像,这在Firefox中可以正确渲染,但在InternetExplorer中不能。img标签必须在一个表中。

    <TABLE>
     <TR>
      <TD>
       <img src="test.gif" width="60%" height="60%">
      </TD>
     </TR>
    </TABLE>
    

    3 回复  |  直到 16 年前
        1
  •  1
  •   brettkelly    16 年前

    请尝试在CSS中定义维度:

    <style type="text/css">
        .myImg{
            width:60%;
            height:60%;
        }
    </style>
    
    <table>
     <tr>
      <td>
       <img src="test.gif" class="myImg" />
      </td>
     </tr>
    </table>
    

    width="200" );

    不管怎样,试试吧-祝你好运

        2
  •  0
  •   Brandon Montgomery    16 年前

    查看上的源代码 http://www.joelonsoftware.com/

        3
  •  0
  •   Holystream    12 年前

    请尝试以下代码:

    <html>
    <head>
      <style>
      table.full-width-table{
        width:100%;
      }
      td.center-text-td{
        text-align: center;
      }
      img.sixty-percent{
        width:60%;
        height:60%;
        margin:0 auto;
      }
      </style>
    </head>
    <body>
      <table class="full-width-table">
      <tbody>
        <tr>
        <td class="center-text-td">
          <img src="test.gif" class="sixty-percent"/>
        </td>
        </tr>
      </tbody>
      </table>
    </body>
    </html>
    
    推荐文章