I have a div
with a fixed width, which has a div
with text inside. Parts of the text are in a span
for coloring. The text div
has all necessary styles for text-overflow with dots at the end (ellipsis), but the dots are not inheriting the span
's color, because their definition is on the div
. When I put the definition on the span
, it ignores its parent's width.
Test code:
.container {
width: 120px;
}
.text {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.color {
color: #b02b7c;
}
<div class="container">
<div class="text">Lorem <span class="color">ipsum dolor sit amet, consetetur</span>
</div>
<!-- works -->
<div>Lorem <span class="text color">ipsum dolor sit amet, consetetur</span>
</div>
<!-- doesn't work -->
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…