html - 将 Thead 部分移动为第一列

标签 html css

考虑以下 html

<table>
<thead>
    <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>data 1.1</td>
        <td>data 1.2</td>
        <td>data 1.3</td>
    </tr>
    <tr>
        <td>data 2.1</td>
        <td>data 2.2</td>
        <td>data 2.3</td>
    </tr>
</tbody>

它呈现如下图:

enter image description here

是否可以只用css让之前的html渲染成下图这样? (请注意指标)

enter image description here

最佳答案

如果你必须用 css 做这件事并且你不能改变你的 HTML 你可以用 Flexbox 来做。

table {
  display: flex;
}
thead tr, tbody tr {
  display: inline-flex;
  flex-direction: column;
}
<table>
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>data 1.1</td>
      <td>data 1.2</td>
      <td>data 1.3</td>
    </tr>
    <tr>
      <td>data 2.1</td>
      <td>data 2.2</td>
      <td>data 2.3</td>
    </tr>
  </tbody>

关于html - 将 Thead 部分移动为第一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41290690/

相关文章:

javascript - 如何在javascript中获取div被点击的部分?

html - CSS 表格单元格等宽

html - CSS下拉菜单显示问题

javascript - Angular JS 不重复背景图像不起作用

java - 为什么 zk 为列表框渲染第二个 tbody?

javascript - Windows 8 应用程序(html 和 Javascript): alternate way to show image from picture library (other that file picker)

javascript - 替换深色背景和正方形

css - HTML 和 CSS 学校元素

css - Firefox:设置了 border-radius 的多个边框相互叠加,显示参差不齐的边缘

html - 3 边上的两个不同宽度的边框