我的顶层布局是n列,所有列的宽度都是固定的(侧边栏),除了中心列(主栏),它应该自动填充剩余的空间。
所以,我在主酒吧有一张棘手的大桌子。它有一个包装
overflow-x: auto
但是,它不触发包装器上的滚动,而是倾向于拉伸
一切
到顶层的柔性容器。这可以通过添加
width: calc(100% - {sum of widths of other columns}px)
到了主栏,但是我正在寻找一个更灵活的解决方案,允许添加更多的列并调整现有列的大小,而不需要点击这个。
calc
规则。
有什么想法吗?有什么方法可以对弹性物品说:
填满剩余的空间,但不要让内容拉伸
?
UPD
:通过将主栏的内容包装在表中
table-layout: fixed
(代码是
here
但是我觉得很不好。有人知道更灵活的解决方案吗?或者这个可以吗?
// this JS generates placeholder text, ignore it
for (const el of document.querySelectorAll(".lorem")) {
el.innerHTML = Array(Number(el.getAttribute("p")) || 1)
.fill()
.map(() => `<p>${chance.paragraph()}</p>`)
.join("");
}
body {
margin: 0;
}
.outer {
display: flex;
}
.sidebar {
flex: 0 0 300px;
background: #eef;
}
.mainbar {
background: #ffe;
/* width: calc(100% - 500px); */
}
.rightbar {
flex: 0 0 200px;
background: #fef;
}
.table-wrapper {
width: 100%;
overflow-x: auto;
background: pink;
}
.table-wrapper td {
min-width: 400px;
}
<script src="https://unpkg.com/chance@1.0.16/chance.js"></script>
<div class="outer">
<div class="sidebar">
<div class="lorem" p="4"></div>
</div>
<div class="mainbar">
<div class="table-wrapper">
<table>
<tr>
<td class="lorem"></td>
<td class="lorem"></td>
<td class="lorem"></td>
<td class="lorem"></td>
</tr>
</table>
</div>
<div class="lorem" p="10"></div>
</div>
<div class="rightbar">
<div class="lorem" p="3"></div>
</div>
</div>