我在flexbox中并排有2个div。右手应始终具有相同的宽度,我希望左手仅抓住剩余空间。除非我专门设置宽度,否则它不会。
因此,现在将其设置为96%,直到您真正按下屏幕为止,它看起来还可以-右div有点饿了它所需的空间。
我想我可以保留原样,但感觉不对,就像必须要说的那样:
正确的人永远是相同的; 你在左边-你得到剩下的一切
.ar-course-nav { cursor: pointer; padding: 8px 12px 8px 12px; border-radius: 8px; } .ar-course-nav:hover { background-color: rgba(0, 0, 0, 0.1); } <br/> <br/> <div class="ar-course-nav" style="display:flex; justify-content:space-between;"> <div style="width:96%;"> <div style="overflow:hidden; white-space:nowrap; text-overflow:ellipsis;"> <strong title="Course Name Which is Really Quite Long And Does Go On a Bit But Then When You Think it's Stopped it Keeps on Going for even longer!"> Course Name Which is Really Quite Long And Does Go On a Bit But Then When You Think it's Stopped it Keeps on Going for even longer! </strong> </div> <div style="width:100%; display:flex; justify-content:space-between;"> <div style="color:#555555; margin-right:8px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;" title="A really really really really really really really really really really really long department name"> A really really really really really really really really really really really long department name </div> <div style="color:#555555; text-align:right; white-space:nowrap;"> Created: 21 September 2016 </div> </div> </div> <div style="margin-left:8px;"> <strong>></strong> </div> </div>
使用该flex-grow属性可以使弹性项目消耗 主轴上的 可用空间。
flex-grow
此属性将尽可能扩展项目,调整长度以适应动态环境,例如调整屏幕大小或添加/删除其他项目。
常见的示例是flex-grow: 1或使用缩写属性flex: 1。
flex-grow: 1
flex: 1
因此,请使用而不是width: 96%在您的div上flex: 1。
width: 96%
你写了:
固定宽度div的压缩与另一个flex属性有关: flex-shrink
flex-shrink
默认情况下,flex项目设置为flex-shrink: 1使它们能够收缩以防止容器溢出。
flex-shrink: 1
要禁用此功能,请使用flex-shrink: 0。
flex-shrink: 0