我有一个嵌套的flex容器,当我的文本不足以显示(https://codepen.io/BigMike/pen/mmMxQN)时,我希望将其截断。
我想要什么
我以为我可以用
来做.truncated {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
有什么建议吗?
答案 0 :(得分:2)
根据您的评论,如果您添加此规则,它将全部停留在一行
.regular {
flex-shrink: 0; /* won't allow element to become smaller than its content */
}
.rows {
display: flex;
flex-wrap: wrap;
}
.child {
flex-basis: 50%;
background-color: red;
min-width: 0px;
}
.nested-row {
display: flex;
padding: 20px;
background-color: blue;
justify-content: space-between;
color: white;
}
.nested-child {
border: solid white 1px;
}
.truncated {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
border: solid white 1px;
min-width: 0;
}
.regular {
flex-shrink: 0;
}
<div class="rows">
<div class="child">
<div class='nested-row'>
<div class="nested-child truncated">
I want this text to truncate but it breaks on a small screen
</div>
<div class='nested-child regular'>
Now this doesn't wrap
</div>
</div>
</div>
<div class="child">
Some other content
</div>
<div class="child">
Some other content
</div>
<div class="child">
Some other content
</div>
</div>
答案 1 :(得分:-1)
问题是白色空间属性。您可以像这样编辑样式表。
.truncated {
overflow: hidden;
text-overflow: ellipsis;
white-space: wrap;
}