content: '>';
in ::after
is clipped by overflow: hidden;
.centered-text {
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 30vw;
}
.centered-text::before {
content: '<';
}
.centered-text::after {
content: '>';
}
<div style="text-align:center;">
<span style="float:left;">I'm on the left</span>
<span class="centered-text">a brown fox jumps over the lazy dog</span>
<span style="float:right;">I'm on the right</span>
</div>
Result:
I'm on the left <a brown fox jumps over th... I'm on the right
The '>'
in ::after
is clipped.
What I expected is ‘>’ is still visible.
I'm on the left <a brown fox jumps over th...> I'm on the right
I had added overflow: visible;
into ::after
to override that in .centered-text
but ‘>’ was still clipped.
3
Answers
@InSync Thank you! The problem of additional wrapper is lots of spaces and disalignment of '<>' if I shorten the message to
<span>a brown fox</span>
.centered-text::after
is considered a child of.centered-text
, which means it will be treated as a normal, actual child element when it comes tooverflow: hidden
.A solution is to wrap the text inside another element and apply styles to that instead:
Try it:
You can use a css variable and use position absolute and set the css variable via javascript.