javascript - 为小屏幕合并表格单元格

标签 javascript html css responsive-design html-table

对于大屏幕,我有这样的东西:

<table>
    <thead>
        <tr>
            <th>title and image</th>
            <th>description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                title
                <br /><img scr="">
            </td>
            <td>
                few words about...
            </td>
        </tr>
    </tbody>
</table>

我想将其更改为以下代码以适应较小的屏幕:

<table>
    <thead>
        <tr>
            <th>title and description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                title
                <br />few words about...
            </td>
        </tr>
    </tbody>
</table>

你知道如何正确地做到这一点吗? :) 我只想用 CSS 来做,但我也可以用 PHP 和 JS 编写代码。

谢谢大家,祝你有美好的一天!

最佳答案

您可以 - 在媒体查询中 - 使用此 CSS 将行转换为单元格并将单元格转换为简单的内联元素:

tr {
  display: table-cell;
}

td {
  display: inline;
}
<table>
  <thead>
    <tr>
      <th>title and image</th>
      <th>description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        title
        <br /><img scr="">
      </td>
      <td>
        few words about...
      </td>
    </tr>
  </tbody>
</table>

关于javascript - 为小屏幕合并表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42870890/

相关文章:

javascript - 隐藏图像直到它们被加载

javascript - Selenium 网络驱动程序 : execute_script can't execute custom methods and external javascript files

JavaScript 关闭内存泄漏

javascript - 尝试打印特定属性时 Node.JS 数组变得未定义

javascript - 在单击的图像顶部应用彩色圆圈

html - 元素未与底部完全对齐;略低于底部边缘

javascript - 无法比较星期五日期 JavaScript

javascript - 如何获取元素位置,如果它以 `margin:auto` 为中心

jquery - 背景图像超出移动屏幕尺寸的内容

javascript - IE11 中的 D3 和弦示例悬停问题