所以目前,这个设置为96%,看起来很好,直到你真的压制了屏幕 – 那么右手的div有点饿了,它需要的空间.
我想我可以离开它,但感觉是错误的 – 就像有一种方式可以说:
the right one is always the same; you on the left – you get everything that’s left
.ar-course-nav { cursor: pointer; padding: 8px 12px 8px 12px; border-radius: 8px; } .ar-course-nav:hover { background-color: rgba(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:1或者使用简写属性flex:1.
因此,而不是宽度:您的div上为96%,请使用flex:1.
你写了:
So at the moment,it’s set to 96% which looks OK until you really squash the screen – then the right hand div gets a bit starved of the space it needs.
固定宽度div的挤压与另一个flex属性有关:flex-shrink
默认情况下,flex项目设置为flex-shrink:1,它们可以缩小,以防止容器溢出.
要禁用此功能,请使用flex-shrink:0.
有关详细信息,请参阅此处的答案中的flex-shrink factor部分:
> What are the differences between flex-basis and width?
在这里了解更多关于主轴的柔性对齐:
> In CSS Flexbox,why are there no “justify-items” and “justify-self” properties?
了解更多有关沿轴的柔性对齐方式:
> How does flex-wrap work with align-self,align-items and align-content?