我如何才能调整表格中 1 或 2 个单元格的大小。我创建了一个具有新宽度的新类,但是当我尝试使用它时没有任何变化。我的代码哪里出错了? 所以问题是我希望 City 和 State 位于同一行且单元格宽度较短,因为现在 State 的输入框在 Last name 的上方并且它不在表中
CSS
<style>
table {
width: auto;
}
table,th, td {
border: 1px solid black;
}
td {
width: 300px !important;
}
th {
width: 120px !important;
text-align: right;
}
.thnewclass {
width: 50px;
}
.cbCell {
width: 15px;
}
input[type="text"] {
width: 270px;
!important;
}
</style>
<table>
<tr>
<th>Last Name</th>
<td class="cbCell">
<input type = "text" name "Last Name" value = "Enter Last Name" />
</td>
</tr>
<tr>
<th>First Name</th>
<td>
<input type = "text" name "First Name" value = "Enter First Name" />
</td>
</tr>
<tr>
<th>Address</th>
<td> <input type = "text" name "Address" /></td>
</tr>
<tr>
<th class = "thnewclass">City</th>
<td class = "thnewclass">
<input type = "text" name "City" />
</td>
<th>State</th>
<input type = "text" name "State">
</tr>
最佳答案
从 td 样式中松开 !important
td {
width: 300px ;
}
th {
width: 120px;
text-align: right;
}
.thnewclass {
width: 50px;
}
关于html - 如何更改表格 HTML/CSS 中 td 的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44923556/