当我使用text-overflow: ellipsis
或display: inline-flex
时,为什么display: flex
无效?我的要求是我必须使用flexbox。
.test {
display: inline-flex;
line-height: 24px;
width: 200px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
background: cyan;
}
<label class="test">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, itaque, at error rerum ab facere cupiditate veniam incidunt modi temporibus explicabo earum molestiae minima facilis a excepturi laborum similique dolore.
</label>
答案 0 :(得分:2)
text-overflow: ellipsis
似乎无法对匿名弹性项目起作用。将文本换行到span
,然后在那里应用省略号。
.test {
display: inline-flex;
line-height: 24px;
width: 200px;
white-space: nowrap;
background: cyan;
}
span {
text-overflow: ellipsis;
overflow: hidden;
}
<label class="test">
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, itaque,
at error rerum ab facere cupiditate veniam incidunt modi temporibus
explicabo earum minima facilis a excepturi laborum similique</span>
</label>
答案 1 :(得分:1)
尝试在父inline-flex
上设置div
,如下所示:
.test {
line-height: 24px;
width: 200px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
background: cyan;
}
.parent-div {
display: inline-flex;
}
<div class="parent-div">
<label class="test">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, itaque, at error rerum ab facere cupiditate veniam incidunt modi temporibus explicabo earum molestiae minima facilis a excepturi laborum similique dolore.
</label>
</div>