简体   繁体   English

如何使用flexbox使块占据剩余宽度

[英]How to make a block take the remaining width with flexbox

So I have the layout close to this one: 因此,我的布局接近此布局:

.wrapper
  .flex
    .flex-item.first
    .flex-item.last
      %p

and css close to this: 和CSS接近这个:

.wrapper {
  min-width: 1100px
  max-width: 1300px
}

.flex {
  display: flex
}

.flex-item.first {
  flex: 0 0 250px;
}

.flex-item.last {
  flex-grow: 5
}

p {
  word-wrap: break-word;
}

and what I am trying to achieve is to make the last flex-item take the remaining width and it works fine, almost ... 我想要实现的是使最后一个弹性项目采用剩余的宽度,并且效果很好,几乎...

If I put a long string in the paragraph tag , I expect it to take the width of the parent and if the line is too long, to transfer text to the next line and it works just like that in Chrome , but in Firefox , this long string makes the second flex-item go outside the allowed width, making it more than 1300px and thus breaking the layout... 如果我在paragraph tag放了一个长字符串,我希望它采用父字符串的宽度,并且如果该行太长,则将文本传输到下一行,其工作原理与Chrome ,但在Firefox ,长字符串使第二个flex-item超出允许的宽度,使其超过1300px ,从而破坏了布局...

PS PS

1)I tried floating the first item to left and adding overflow to the last item and it worked ok ( not without complications ) but flexbox seems easier to work with, I guess ... 1)我尝试将第一个项目浮动到左侧并向最后一个项目添加溢出,并且它工作正常(并非没有并发症),但是flexbox似乎更容易使用,我想...

2) The number 5 for flex-grow is random, just made it big enough to make it take the remaining space 2)flex-grow的数字5是随机的,只是使其足够大以占用剩余空间

Link to Fiddle: https://jsfiddle.net/afj88pc5/ 链接到Fiddle: https : //jsfiddle.net/afj88pc5/

Use following css will works: 使用以下CSS将起作用:

p {
    word-wrap: break-word;
    word-break: break-all;
}

Check your updated Fiddle here. 在这里检查更新的小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM