代码示例:
.flex {
display: flex;
}
.flex-img {
width: 200px;
height: 200px;
}
.flex-text {
min-width: 0; // 关键点
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<div className="flex">
<img className="flex-img" src="" alt="" />
<div className="flex-text">
省略号省略号省略号省略号省略号省略号省略号省略号省略号省略号
</div>
</div>
在样式设置了flex: 1
的元素添加 min-width: 0
就会出现省略号了。