1

我有一个表格,其中第二列应该有一定的宽度(例如 50px)。当我在此列中有一个宽度为 100% 的文本框,但有很多文本时,该列的宽度始终与文本一样长。

看我的代码+截图

<!DOCTYPE HTML>
<html>
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Test</title>
</head>

<body>


<table border="1">
  <tr>
  <td></td>
  <td style="width:50px;"><input type="text" value="very long text which doesn't fit into the whole textbox" style="width:100%" />
  </td>
  </tr>
</table>

</body>
</html>

在此处输入图像描述

如何在 IE7 中强制列为 50px 长?

4

1 回答 1

0

您可以通过使用 IE 条件注释来实现这一点,如下所示

<!DOCTYPE HTML>
<html>
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Test</title>    
    <style>
        .myInput{width: 100%;}
    </style>
    <!--[if IE 7]>
        <style>          
            .myInput{width: 50px;}
        </style>
    <![endif]-->
</head>

<body>
<table border="1">
  <tr>
  <td></td>
  <td style="width:50px;"><input class="myInput" type="text" value="very long text which doesn't fit into the whole textbox"/>
  </td>
  </tr>
</table>
</body>
</html>

我已经在 IE 测试仪上检查了这个,看起来很好。希望这可以帮助!

于 2014-04-03T07:56:18.433 回答