【问题标题】:thead with one td (full width) and tbody with 2 columns (width not depending on thead)具有 1 个 td(全宽)和 2 列的 tbody(宽度不取决于 thead)
【发布时间】:2013-07-28 06:02:37
【问题描述】:

好的,长篇短篇小说。我的表格结构如下:

<table>
<thead>
<tr><th>longer Heading with a width of 100%</th></tr>
</thead>
<tbody>
<tr><td>cell 1</td><td>cell 2</tr>
<tr><td>cell 3</td><td>cell 4</tr>
</tbody>
</table>

我希望 th 是全宽的,而不是改变表格单元格的宽度。 我想有一些 CSS 显示属性可以使这成为可能,但我还没有找到可行的解决方案。

【问题讨论】:

  • 完成,找到直接放在表格开头之后的标题标签

标签: html html-table


【解决方案1】:

比这更简单:您只需要在 th 元素上添加一个 colspan。
Colspan 定义了元素扩展了多少个单元格:

<table>
    <thead>
        <tr><th colspan="2">longer Heading with a width of 100%</th></tr>
    </thead>
    <tbody>
        <tr><td>cell 1</td><td>cell 2</tr>
        <tr><td>cell 3</td><td>cell 4</tr>
    </tbody>
</table>

See my Fiddle

【讨论】:

    【解决方案2】:

    这个?

    <th colspan="2">...</th>
    

    【讨论】:

      【解决方案3】:
      <table>
        <thead>
           <tr><th colspan="2">longer Heading with a width of 100%</th></tr>
        </thead>
        <tbody>
           <tr><td>cell 1</td><td>cell 2 </td></tr>
            <tr><td>cell 3</td><td>cell 4 </td></tr>
       </tbody>
      

      使用colspan 会为您解决问题

      【讨论】:

        猜你喜欢
        • 2013-11-16
        • 2012-12-10
        • 2018-02-22
        • 2018-01-03
        • 2013-01-04
        • 1970-01-01
        • 2019-07-20
        • 1970-01-01
        • 2023-03-24
        相关资源
        最近更新 更多