【发布时间】:2017-02-11 19:53:59
【问题描述】:
我有一个使用 flexbox 创建的两列布局。
在右栏中,我有两行,第一行包含标题,第二行包含页面内容。
在标题中我有三列、一个按钮、一些文本和一个按钮。
我希望按钮位于列的左侧和右侧,文本占用任何额外的空间。
最后,我希望文本具有white-space:nowrap 和text-overflow:ellipsis 属性来截断长标题。
我的问题是这样的:我无法让文本换行在嵌套在另一个 flexbox 中的 flexbox 中正常工作,如下小提琴所示:
http://jsfiddle.net/maxmumford/rb4sk3mz/3/
.container {
display: flex;
height: 100vh;
}
.left {
width: 200px;
background-color: yellow;
}
.right {
flex: 1;
background-color: blue;
color: white;
}
.header {
background: red;
color: white;
display: flex;
flex-direction: row;
}
.header .content {
white-space: nowrap;
flex: 0 1 auto;
text-overflow: ellipsis;
overflow: hidden;
min-width: 0;
}
.header .buttons {
background: green;
flex: 1 0 auto;
}
.header .content:hover {
white-space: normal;
}
<div class="container">
<div class="left">
content left
</div>
<div class="right">
<div class="header">
<div class="buttons">buttons</div>
<div class="content">
This content is really long and should wrap with ellipses, but for some reason it doesn't work when it's nested in a container with display: flex
</div>
<div class="buttons">buttons</div>
</div>
content right
</div>
</div>
但是,当标头未嵌套在弹性框中时,完全相同的代码可以工作:
http://jsfiddle.net/maxmumford/p7115f2v/1/
.header {
background: red;
color: white;
display: flex;
flex-direction: row;
}
.header .content {
white-space: nowrap;
flex: 0 1 auto;
text-overflow: ellipsis;
overflow: hidden;
min-width: 0;
}
.header .buttons {
background: green;
flex: 1 0 auto;
}
<div class="header">
<div class="buttons">buttons</div>
<div class="content">
This content is really long and is wrapped correctly... This content is really long and is wrapped correctly... This content is really long and is wrapped correctly... This content is really long and is wrapped correctly... This content is really long
and is wrapped correctly... This content is really long and is wrapped correctly... This content is really long and is wrapped correctly...
</div>
<div class="buttons">buttons</div>
</div>
我怎样才能在第一小提琴中实现我想要的?
谢谢
【问题讨论】: