gpt4 book ai didi

html - 文本溢出 : ellipses does not work when parent width is fixed and child width is dynamic

转载 作者:太空宇宙 更新时间:2023-11-03 19:27:58 24 4
gpt4 key购买 nike

我有一个 parent <div>有多个 child span秒。父 div 的宽度是固定的,但子 span 的宽度可以是动态的。我试过的方式,文本溢出:省略号似乎对 child 不起作用。

<div class="parent">
<span class="child1"> Content 1</span>
<span class="child2"> Content 2</span>
<span class="child3"> Content 3</span>
</div>


.parent {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
max-width: 200px;
display: inline-block;
}

span {
display: inline-block;
}

JsFiddle .

最佳答案

text-overflow不是 inherited属性(property)。这意味着您分配给它的值仅适用于父元素 (.parent) 但不适用于其子元素 (span)。

要解决您的问题,只需将该属性向下移动到子项即可。例如(取决于您的上下文)您可以这样编码:

.parent {  
border: 1px solid red;
}

span {
display: inline-block;
text-overflow: ellipsis;
white-space: nowrap;
width: 50px;
border: 1px solid blue;
overflow: hidden;
}

关于html - 文本溢出 : ellipses does not work when parent width is fixed and child width is dynamic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44744831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com