A customer sent me a font where the '...'-character is not defined (it only shows up a mirror-inverted '3'). So i wanted to do something like:
.myclass ul li{
text-overflow: ellipsis;
text-overflow-content: '...';
}
any idea, how I can do this?
You can set the value of text-overflow
to a string, like:
.myclass ul li{
text-overflow: '...';
}
However:
In the draft, it even says:
Note: The
<string>
value, and the 2-value syntax"{1,2}"
and functionality are all at risk.
Because of this, I'd just use a class if the overflow doesn't have to be dynamic, or JS if it does.
JS Solution
let p = document.querySelector(".js-overflow");
// Add overflow class if needed
if (p.scrollWidth > p.offsetWidth) p.classList.add("has-overflow");
while (p.scrollWidth > p.offsetWidth) {
// Remove characters from paragraph until the text and the overflow indicator fit
p.innerHTML = p.innerHTML.slice(0, -1);
}
p {
width: 200px;
border: 1px solid;
padding: 2px 5px;
/* BOTH of the following are required for text-overflow */
white-space: nowrap;
overflow: hidden;
}
.has-overflow:after {
content: "..."
}
<p class="js-overflow">
Simple string to test text overflow, will overflow to your custom string at 200px.
</p>
A JS solution is quite simple:
after
pseudo elements content is less than the width.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With