【问题标题】:Flex wrap within tbody IEtbody IE 中的 Flex 换行
【发布时间】:2019-07-15 20:00:11
【问题描述】:

Flex wrap 在 IE 11 中的表的 tbody 中不起作用。我尝试了其他堆栈溢出帖子的不同建议,但没有一个有用。

如果您在 chrome/firefox/edge 中打开此 URL,您可以看到 flex wrap 工作正常,但在 IE 11 左右它不会 https://liveweave.com/j2yzx0

我也尝试使用this 作为参考,但没有多大用处。

* {
  box-sizing: border-box;
}

table {
  table-layout: fixed;
  width: 100%;
  border: 1px solid black;
}

tr {
  border: 1px solid blue;
  display: flex;
  flex-wrap: wrap;
  margin: 10px 0px;
}

th,
td {
  border: 1px solid red;
  text-align: center;
  flex-basis: 26%;
}
<table>
  <thead>
    <tr>
      <th>Col 1</th>
      <th>Col 2</th>
      <th>Col 3</th>
      <th>Col 4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>R1C1</td>
      <td>R1C2</td>
      <td>R1C3</td>
      <td>R1C4</td>
    </tr>
    <tr>
      <td>R2C1</td>
      <td>R2C2</td>
      <td>R2C3</td>
      <td>R2C4</td>
    </tr>
  </tbody>
</table>

我什至尝试添加显示块、-ms- 前缀等但无济于事 链接在这里:https://liveweave.com/Liylfz

* {
  box-sizing: border-box;
}

table,
tbody,
thead,
td,
th {
  display: block;
}

table {
  border: 1px solid black;
  width: 100%;
}

thead,
tbody {
  display: block;
}

tr {
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

th,
td {
  border: 1px solid red;
  text-align: center;
  padding: 5px;
  background-color: #eee;
  width: 50%;
  flex-basis: 50%;
}
<table>
  <thead>
    <tr>
      <th>Col 1</th>
      <th>Col 2</th>
      <th>Col 3</th>
      <th>Col 4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>R1C1</td>
      <td>R1C2</td>
      <td>R1C3</td>
      <td>R1C4</td>
    </tr>
    <tr>
      <td>R2C1</td>
      <td>R2C2</td>
      <td>R2C3</td>
      <td>R2C4</td>
    </tr>
  </tbody>
</table>

【问题讨论】:

  • 使用 float: left 似乎有帮助,但由于使用 order 设置 flex 顺序不起作用,因此似乎没有任何 flex 属性起作用。

标签: html css internet-explorer flexbox


【解决方案1】:

在 IE11 中,当 flex 项目table-cell 作为它们的显示 时,它不会像它那样blockifieddisplay: block通常在 Chrome 或 Firefox 中运行。在此处检查 thtd 元素后,您可以通过查看开发人员工具中的计算样式来验证这一点。

只需在此处将display: block 添加到th,td - 请参见下面的演示:

* {
  box-sizing: border-box;
}

table {
  table-layout: fixed;
  width: 100%;
  border: 1px solid black;
}

tr {
  border: 1px solid blue;
  display: flex;
  flex-wrap: wrap;
  margin: 10px 0px;
}

th,
td {
  border: 1px solid red;
  text-align: center;
  flex-basis: 26%;
  display: block; /* ADDED */
}
<table>
  <thead>
    <tr>
      <th>Col 1</th>
      <th>Col 2</th>
      <th>Col 3</th>
      <th>Col 4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>R1C1</td>
      <td>R1C2</td>
      <td>R1C3</td>
      <td>R1C4</td>
    </tr>
    <tr>
      <td>R2C1</td>
      <td>R2C2</td>
      <td>R2C3</td>
      <td>R2C4</td>
    </tr>
  </tbody>
</table>

【讨论】:

  • 我之前已经试过了,我又试了一次,很遗憾没有成功
  • 我不知道为什么它在 liveweave 中不起作用,但在上面的 sn-p 和 this fiddle too 中它在 IE11 中起作用
  • 你是对的。在上面的代码 sn-p 中,它似乎在 IE11 中工作。
  • 我会进行一些测试,看看是否是 liveweave 的问题或某些特殊情况,然后会给出答案:) 谢谢
猜你喜欢
  • 1970-01-01
  • 2011-06-11
  • 2011-10-17
  • 1970-01-01
  • 1970-01-01
  • 2014-10-11
  • 2019-08-23
  • 2020-03-16
  • 2014-11-18
相关资源
最近更新 更多