html - Flex wrap within tbody IE
问题描述
Flex wrap is not working within tbody
of a table in IE 11. I tried different suggestions from other stack overflow posts but none of them were useful.
If you open this URL in chrome/firefox/edge you can see flex wrap working fine but in IE 11 or so it doesn't https://liveweave.com/j2yzx0
I tried using this as reference too but not of much use.
* {
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>
I even tried adding display block, -ms- prefix etc but to no avail Link here: 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>
解决方案
在 IE11 中,当flex项目作为table-cell
它们的display时,它不会像在 Chrome 或 Firefox 中那样被阻止。display: block
您可以通过在此处检查or元素后查看开发人员工具中的计算样式来验证这一点。th
td
只需添加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>
推荐阅读
- javascript - 渲染一组 HTML 元素/对象以做出反应
- amazon-elastic-beanstalk - 重定向到 aws elastic beanstalk 上的子域或子目录
- mysql - MySQL:提取列中的值更改的日期
- reactjs - EventEmitter.removeListener('change', ...)
- job-scheduling - 如何抽象 Autosys 的工作所有者?
- slug - Sveltekit slug 在根文件夹中并构建静态站点
- javascript - 在 Safari 上使用 Angular 管道时括号工作错误
- javascript - Handsontable(6.2.2) manualColumnMove 不起作用
- r - 使用 group_by、summary 和 max() 循环 R 中的字符向量
- javascript - el.getBoundingClientRect 不是反应里程表 js 中带有反应可见性传感器的函数吗?