html – 在flexbox中使div填充剩余* horizo​​ntal *空格

发布时间:2020-01-24 发布网站:脚本之家
脚本之家收集整理的这篇文章主要介绍了html – 在flexbox中使div填充剩余* horizo​​ntal *空格脚本之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在flexbox中并排配置了2个div.右手一般应该是宽度相同的,我要左手拿一个剩下的空间.但是除非我专门设置宽度,否则不会.

所以目前,这个设置为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>&gt;</strong>
  </div>
</div>

解决方法

使用flex-grow属性使flex项目在主轴上消耗可用空间.

该属性将尽可能扩展项目,将长度调整为动态环境,如屏幕重新调整或添加/删除其他项目.

一个常见的例子是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?

总结

以上是脚本之家为你收集整理的html – 在flexbox中使div填充剩余* horizo​​ntal *空格全部内容,希望文章能够帮你解决html – 在flexbox中使div填充剩余* horizo​​ntal *空格所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:76874919,请注明来意。
标签: