【发布时间】:2019-10-19 05:47:48
【问题描述】:
当我在 .container 上没有 display: flex 时,文本会在减小容器大小时正确截断。
但是绿色块和文本不再相邻,因为容器没有display: flex。当我将它添加到容器中时,绿色块和文本正确对齐,但文本不再被截断(省略号丢失)。
如何使用 flex 确保块和文本对齐,但文本在动态宽度容器中被省略号截断?
body {
padding: 20px;
}
.container {
display: flex;
}
.block {
width: 25px;
height: 25px;
padding: 10px;
background-color: yellowgreen;
display: flex;
align-items: center;
justify-content: center;
margin-right: 20px
}
.text {
display: flex;
}
.truncate {
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 20pt;
}
<div class="container">
<div class="block">B</div>
<div class="text">
<div class="truncate">
3. This is a long string that is OK to truncate please and thank you
</div>
</div>
</div>
【问题讨论】:
标签: html css flexbox overflow ellipsis