TD宽度不随输入字段而变化

时间:2014-09-10 13:27:09

标签: html css

我的目标是让每个TD的宽度 100px ,这也应该使输入字段 100px 。但是,当我将width="100"添加到TD时,没有任何反应。这是HTML代码:

<table>
    <tr>
        <td>2.</td>
        <td width="100">
            <input type="text" name="year2" id="year2" value="" />
        </td>
        <td width="100">
            <input type="text" name="make2" id="make2" value="" />
        </td>
        <td width="100">
            <input type="text" name="vin2" id="vin2" value="" />
        </td>
        <td width="100">
            <input type="text" name="radius2" id="radius2" value="" />
        </td>
        <td width="100">
            <input type="text" name="gvm2" id="gvm2" value="" />
        </td>
        <td width="100">
            <input type="text" name="comp2" id="comp2" value="" />
        </td>
        <td width="100">
            <input type="text" name="coll2" id="coll21" value="" />
        </td>
        <td width="100">
            <input type="text" name="amt2" id="amt2" value="" />
        </td>
    </tr>
</table>

以下是JSFiddle

的链接

我将不胜感激。

2 个答案:

答案 0 :(得分:1)

style="width: 100px"添加到每个input或添加到您的css文件

input[type="text"]{
    width: 100px;
}

第二个选项

fiddle

答案 1 :(得分:1)

应在<input>上添加样式,而不是<td>。您还应该通过CSS来管理它,而不是使用内联样式。

在CSS中添加

.my-width {
    width: 100px;
}

然后将该类添加到每个输入中:

<input class="my-width" type="text" name="year2" id="year2" value="" />

<强> JS Fiddle Demo

相关问题