我正在尝试设置一个具有三列的 flexbox 布局,其中左右列具有固定宽度,中间列弯曲以填充可用空间。
尽管为列设置了尺寸,但它们似乎仍会随着窗口缩小而缩小。
任何人都知道如何做到这一点?
我需要做的另一件事是根据用户交互隐藏右列,在这种情况下,左列仍将保持其固定宽度,但中间列将填充其余空间。
#container {
display: flex;
justify-content: space-around;
align-items: stretch;
max-width: 1200px;
}
.column.left {
width: 230px;
}
.column.right {
width: 230px;
border-left: 1px solid #eee;
}
.column.center {
border-left: 1px solid #eee;
}
<div id="container">
<div class="column left">
<p>Anxiety was a blog series that ran in the New York Times Opinion section from January 2012 to July 2013. It featured essays, fiction, and art by a wide range of contributors that explored anxiety from scientific, literary, and artistic perspectives.</p>
</div>
<div class="column center">
<img src="http://i.imgur.com/60PVLis.png" width="100" height="100" alt="">
</div>
<div class="column right">
Balint Zsako
<br/> Someone’s Knocking at My Door
<br/> 01.12.13
</div>
</div>
这是一个 JSFiddle:http: //jsfiddle.net/zDd2g/185/
原文由 mheavers 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用
flex: 0 0 230px;
而不是使用width
(这是使用 flexbox 时的建议),这意味着:0
= 不增长(flex-grow
的简写)0
= 不缩小(flex-shrink
的简写)230px
= 从230px
flex-basis
简写)这意味着:总是
230px
。看小提琴,谢谢@TylerH
哦,你不需要
justify-content
和align-items
在这里。