<分区>
<分区>
我知道这些帖子:
没有答案可以解决我在下面的代码片段中遇到的问题。这是 html 树:
唯一能让它工作的方法是将标签设为 inline-block
,但我真的很想保留 flex。
我已经做了什么:
空白:nowrap
最小宽度:0
溢出:隐藏
最小宽度:0
flex-grow: 1
和 max-width: 100%
.parent-container {
align-items: stretch;
display: flex;
flex-flow: column nowrap;
width: 100%;
}
.item-container {
border: 1px solid #ebf0ff;
border-radius: 0.25rem;
display: flex;
flex-flow: row nowrap;
height: 3.25rem;
margin: 0.5rem 1rem;
padding: 0.5rem 1rem;
}
.label {
align-items: center;
display: flex;
flex-flow: row nowrap;
font-family: sans-serif;
font-weight: 500;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<!DOCTYPE HTML>
<html>
<body>
<div class="parent-container">
<div class="item-container">
<span class="label">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span>
</div>
</div>
</body>
</html>
最佳答案
您需要为 .label
删除 flex
并对齐,使用 align-items: center;
作为其父项。
.parent-container {
align-items: stretch;
display: flex;
flex-flow: column nowrap;
width: 100%;
}
.item-container {
border: 1px solid #ebf0ff;
border-radius: 0.25rem;
display: flex;
align-items: center;
flex-flow: row nowrap;
height: 3.25rem;
margin: 0.5rem 1rem;
padding: 0.5rem 1rem;
}
.label {
flex-flow: row nowrap;
font-family: sans-serif;
font-weight: 500;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<!DOCTYPE HTML>
<html>
<body>
<div class="parent-container">
<div class="item-container">
<span class="label">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span>
</div>
</div>
</body>
</html>
关于html - 文本溢出 : ellipsis not working on nested flex container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58965720/