为了理解 flex 是如何工作的,我们应该做一些测试。因此,我将构建一些示例。
首先重要的是要知道 flex 容器方向的默认行为设置为row
. 这意味着 flex 容器内的所有子元素将尽可能长时间地彼此相邻放置。此外,在使用 flexbox 时,我们不再考虑左或右。我们不考虑主轴和交叉轴。
主轴是方向,子元素是布局的。因此,默认情况下,它将是从左到右。
那么交叉轴将从上到下。
接下来重要的是要知道,默认情况下,flex 容器内的子元素只占用所需的空间。
/* just for some nice looking */
* {
font-family: sans-serif;
box-sizing: border-box;
}
.flex-container {
display: flex;
width: 100%;
padding: 1rem;
background: #666;
}
.flex-item {
padding: 0.5rem;
font-weight: bold;
color: white;
}
.r {
background: red;
}
.g {
background: darkgreen;
}
.b {
background: blue;
}
<div class="flex-container">
<div class="flex-item r">blue</div>
<div class="flex-item g">red</div>
<div class="flex-item b">green</div>
</div>
既然现在我们知道了 flex 容器和子元素的默认行为,让我们看看我们必须做些什么来使文本对齐工作。
一种方法是拉伸子元素,使里面的文本有足够的空间进行对齐。
我们可以使用flex-grow
子元素的属性来做到这一点:
/* just for some nice looking */
* {
font-family: sans-serif;
box-sizing: border-box;
}
.flex-container {
display: flex;
width: 100%;
padding: 1rem;
background: #666;
}
.flex-item {
padding: 0.5rem;
font-weight: bold;
color: white;
}
.r {
background: red;
}
.g {
background: darkgreen;
}
.b {
background: blue;
}
/* Updated content */
.flex-item {
flex-grow: 1;
}
.r {
text-align: left;
}
.g {
text-align: center;
}
.b {
text-align: right;
}
<div class="flex-container">
<div class="flex-item r">blue</div>
<div class="flex-item g">red</div>
<div class="flex-item b">green</div>
</div>
所以在你的情况下,我们可以display: flex
从.data-row-cell
类中删除并添加一些flex-grow: 1
请查看我更新的小提琴:
https ://jsfiddle.net/7wfm1s0j/
我希望它有帮助:-)