[英]Flexbox div text wrapping
I want to make text in my flexbox layout wrap. 我想在我的flexbox布局包中制作文本。
Code: https://jsfiddle.net/u2oswnth/2/ 代码: https : //jsfiddle.net/u2oswnth/2/
.child { border: solid 1px; display: flex; } .left { width: 100px; } .container { display: flex; flex-wrap: wrap; }
<div class="container"> <div class="child left"> Left! </div> <div class="child right"> I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! </div> </div>
What I have: When exceeding frame width, .right
div
falls to next row. 我拥有:超过帧宽时,
.right
div
下降到下一行。
What I want: When exceeding frame width, words in .right
div
start wrapping, two columns stay side-by-side, forming single row. 我想要的:当超过框架宽度时,
.right
div
单词开始包装,两列并排,形成单行。
Change flex-wrap: wrap;
改变
flex-wrap: wrap;
to flex-wrap: nowrap;
flex-wrap: nowrap;
. 。 By using
flex-wrap: wrap;
通过使用
flex-wrap: wrap;
you are telling the .right
div
to wrap onto a new line if it runs out of space. 你告诉
.right
div
如果空间.right
新的一行。 As you only want the text itself to wrap you need to use flex-wrap: nowrap;
因为你只想要文本本身包装你需要使用
flex-wrap: nowrap;
to keep .right
on the same line. 保持
.right
在同一条线上。 The text will automatically wrap when there is not enough space. 当空间不足时,文本将自动换行。
flex-wrap: wrap;
flex-wrap: wrap;
to flex-wrap: nowrap;
flex-wrap: nowrap;
on .container
.container
.child { border: solid 1px; display: flex; } .left { width: 100px; } .container { display: flex; flex-wrap: nowrap; }
<div class="container"> <div class="child left"> Left! </div> <div class="child right"> I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! </div> </div>
NOTE: There is no need to apply "display: flex"
on child class and flex-wrap: nowrap;
注意:不需要在子类和
flex-wrap: nowrap;
上应用"display: flex"
flex-wrap: nowrap;
on container class because bydefault it is nowrap
. 在容器类上,因为默认它是
nowrap
。 Below is updated answer and WORKS!!. 下面是更新的答案和WORKS !!
.child {
border: solid 1px;
}
.left {
width: 100px;
}
.container {
display: flex;
}
<div class="container">
<div class="child left">
Left!
</div>
<div class="child right">
I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! I'm riiiight!!! I'm riiiight!!!
</div>
</div>
You should change flex-wrap: wrap;
你应该改变
flex-wrap: wrap;
to flex-wrap: nowrap;
flex-wrap: nowrap;
Please note that flex-wrap: no-wrap;
请注意,
flex-wrap: no-wrap;
( no-wrap with a dash ) is NOT a valid value. ( 没有用破折号包裹 )不是有效值。 Here's the doc reference about it: https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap
这是关于它的文档参考: https : //developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.