【发布时间】:2020-03-03 04:59:16
【问题描述】:
我有 3 个弹性项目。 2 应根据其内容调整大小并并排显示。另一个弹性项目应该增长到适合这个宽度(但不会更多。)
我想要什么:
目前的样子:
我能够靠近,但仍有一些灰色背景显示(似乎没有考虑文字)。 https://codepen.io/albrechtnate/pen/abbYeYL
.container {
display: flex;
width: fit-content;
flex-flow: row wrap;
}
.container div:first-child {
width: 100%;
}
/* Un-related Styles */
.setup {
background-color: #ccc;
}
.setup div {
height: 100px;
background-color: blue;
}
.setup div:first-child {
background-color: red;
}
.setup div:last-child {
background-color: green;
}
<div class="container setup">
<div>Item</div>
<div>Item Two</div>
<div>Item Three</div>
</div>
我确实使用 CSS Grid (https://codepen.io/albrechtnate/pen/zYYWgEZ) 让它工作,但对于这样的事情,Grid 感觉有点矫枉过正。如果我添加第 4 项,我不想更改网格模板列。
【问题讨论】: