html - 如何更改表格 HTML/CSS 中 td 的默认值

标签 html css

我如何才能调整表格中 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;
}

Demo

关于html - 如何更改表格 HTML/CSS 中 td 的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44923556/

相关文章:

javascript - 使用 setTimeout 重新加载图像

css - 如何为样式表中的所有样式生成引用页

asp.net - 如何更改 ASP.NET ListView 中特定 <li> 的类?

html - 我的 CSS 不会显示 : inline; for my buttons

html - 为什么 &lt;textarea&gt; 和 &lt;input&gt; 元素不遵守最大宽度?

html - 个人数据使用的表单字段名称在浏览器中自动填写(Safari、Opera)

html - Highcharts 堆积柱突出显示

html - 使用 CSS 的 Bootstrap 3 Grid 中的垂直 DIV 对齐

html - 将 x2 图像用于 Retina 显示 CSS

javascript - LTR 到 RTL jQuery Collapsibles block