I've created an anchor with a ::before
pseudo-element used for an SVG icon. When ::before
is both position: relative
and positioned with either a negative value when using top/left or a positive value when using bottom/right, the text-overflow: ellipsis
functionality breaks.
a {
display: block;
border: 1px solid blue;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
width: 200px;
}
a::before {
content: '';
display: inline-block;
width: 20px;
height: 20px;
border: 1px solid red;
position: relative;
}
a.test2::before, a.test3::before {
left: -1px;
}
a.test3::before {
position: absolute;
}
<a class="test1">some very long text which overflows</a>
<a class="test2">some very long text which overflows</a>
<a class="test3">some very long text which overflows</a>
For example, the text should overflow and get an ellipsis in each of these examples but the second one breaks (at least in Chrome 61, macOS).
It seems that Firefox 56 on mac does not have this issue.
Using position: absolute
or some other variations solve the issue, but I can't find much explanation for why this happens.