html - 为什么为表格列设置 flex 显示会破坏表格结构?

标签 html css flexbox

如果第 2 列和第 3 列设置为 3 列表格中的 flex 元素,则表格结构会中断,并且第 3 列会滑到第 2 列下方,从而失去类似表格的结构。为什么会这样?

table {
  width: 500px;
  background-color: red;
}

.first {
  width: 100px;
}

.second {
  display:flex;
  background-color:blue;
}

.third {
  display:flex;
  background-color: green;
}
<table>
  <tr>
    <td class="first">asdad<td>
    <td class="second"> asdasd</td>
    <td class="third"> asdads</td>
  </tr>
</table>

我希望得到 3 列,并且我可以在其中放置 flex 元素。

最佳答案

您将 display:table-cell 的行为更改为 display:flex,因为这 2 列正在合并为单个列。您可以使用下面的代码片段

<table><tr><td class="first">asdad<td><td class="second"><div>asdasd</div></td><td class="third"><div>asdads</div></td></tr></table>


.second > div {display:flex; background-color:blue;}
.third  > div{display:flex;background-color: green;}

https://jsfiddle.net/ulric_469/jtxckL8p/3/

关于html - 为什么为表格列设置 flex 显示会破坏表格结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56218126/

相关文章:

html - 全屏 div 下的 Div 为 "fixed or absolute"?

html - 如何使 div 使用 100% 的可用高度?

javascript - 我需要帮助使用 VS-2013 在服务器上部署我的 asp.net 网站

html - 如何防止打印::在 css 之后?

html - 如何将 flex 容器居中但左对齐 flex 元素

html - CSS Flex 拉伸(stretch)链接

html - 布局 Jade 导航栏

html - 指定网格中的行数和列数

html - contenteditable 的中心内容

jquery - 如何从卡片或类似的东西中获取标题以与 flexbox 具有相同的高度?