引导表的IE11 Flex问题

时间:2019-01-29 19:56:25

标签: html css flexbox bootstrap-4 internet-explorer-11

在使用引导表时,我遇到IE11和Flexbox的问题。

我的行是这样的

enter image description here

我在设计中有一个表,由于其中包含许多字段,因此可以向右滚动。使用col设置的flex使其可以保留列宽。

如下面的图片所示,它在Chrome和Firefox中运行良好。

enter image description here

在IE中,由于tbody行相对于thead行的移动方式不同,因此它已损坏。两者都具有与第一张图片相同的结构和类。

enter image description here

任何想法如何解决这个问题?我必须在当前项目中支持IE11,这确实很痛苦。

更新: 这是表格的代码:

<table class="table-responsive table-sm">
        <thead>
        <tr class="d-flex">
            <th class="col-1">Bla 1</th>
            <th class="col-2">Bla 2</th>
            <th class="col-2">Bla 3</th>
            <th class="col-2">Bla 4</th>
            <th class="col-2">Bla 5</th>
            <th class="col-1">Bla 6</th>
            <th class="col-1">Bla 7</th>
            <th class="col-3">Bla 8</th>
            <th class="col-3">Bla 9</th>
            <th class="col-1">Bla 10</th>
            <th class="col-3">Bla 11</th>
            <th class="col-3">Bla 12</th>
            <th class="col-3">Bla 13</th>
            <th class="col-3">Bla 14</th>
            <th class="col-2">15</th>
        </tr>
        </thead>
        <tbody>
        {% for item in bla %}
            <tr class="d-flex">
                <td class="col-1">{{ item.bla1 }}</td>
                <td class="col-2"></td>
                <td class="col-2">{{ item.bla3 }}</td>
                <td class="col-2">{{ item.bla4 }}</td>
                <td class="col-2">{{ item.bla5 }}</td>
                <td class="col-1">{{ item.bla6 }}</td>
                <td class="col-1">{{ item.bla7 }}</td>
                <td class="col-3">{{ item.bla8 }}</td>
                <td class="col-3">{{ item.bla9 }}</td>
                <td class="col-1">{{ item.bla10 }}</td>
                <td class="col-3">{{ item.bla11 }}</td>
                <td class="col-3">{{ item.bla12 }}</td>
                <td class="col-3">{{ item.bla13 }}</td>
                <td class="col-3">{{ item.bla14 }}</td>
                <td class="col-2">{{ item.bla15 }}</td>
            </tr>
        {% else %}
            <tr>
                <td colspan="14">no records found</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

1 个答案:

答案 0 :(得分:1)

我用这种风格弄清楚了:

    td , th {
        display: block;
    }

    thead , tbody {
        display: flex;
    }

    tr {
        width: 100%;
    }

解决方案2将像这样为每个col设置一个静态宽度:

th.col-1 , td.col-1 {
    min-width: 100px;
    max-width: 100px;
}

th.col-2 , td.col-2 {
    min-width: 150px;
    max-width: 150px;
}

th.col-3 , td.col-3 {
    min-width: 200px;
    max-width: 200px;
}

使用解决方案1的代码:

	td , th {
		display: block;
	}

	thead , tbody {
		display: flex;
	}

	tr {
		width: 100%;
	}
/*
	th.col-1 , td.col-1 {
		min-width: 100px;
		max-width: 100px;
	}

	th.col-2 , td.col-2 {
		min-width: 150px;
		max-width: 150px;
	}

	th.col-3 , td.col-3 {
		min-width: 200px;
		max-width: 200px;
	}
*/
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

	<style type="text/css">


  </style>
</head>
<body>

	<table class="table-responsive table-sm">
		<thead>
			<tr class="d-flex">
				<th class="col-1">Bla 1</th>
				<th class="col-2">Bla 2</th>
				<th class="col-2">Bla 3</th>
				<th class="col-2">Bla 4</th>
				<th class="col-2">Bla 5</th>
				<th class="col-1">Bla 6</th>
				<th class="col-1">Bla 7</th>
				<th class="col-3">Bla 8</th>
				<th class="col-3">Bla 9</th>
				<th class="col-1">Bla 10</th>
				<th class="col-3">Bla 11</th>
				<th class="col-3">Bla 12</th>
				<th class="col-3">Bla 13</th>
				<th class="col-3">Bla 14</th>
				<th class="col-2">Bla 15</th>
			</tr>
		</thead>
		<tbody>
			<tr class="d-flex">
				<td class="col-1">Bla 1</td>
				<td class="col-2">Bla 2</td>
				<td class="col-2">Bla 3</td>
				<td class="col-2">Bla 4</td>
				<td class="col-2">Bla 5</td>
				<td class="col-1">Bla 6</td>
				<td class="col-1">Bla 7</td>
				<td class="col-3">Bla 8</td>
				<td class="col-3">Bla 9</td>
				<td class="col-1">Bla 10</td>
				<td class="col-3">Bla 11</td>
				<td class="col-3">Bla 12</td>
				<td class="col-3">Bla 13</td>
				<td class="col-3">Bla 14</td>
				<td class="col-2">Bla 15</td>
			</tr>
		</tbody>
	</table>

	<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>
</html>