I know we can limit text to certain characters using Ellipsis or even use JavaScript. But I am wondering if there is no JavaScript available, and I don’t want Ellipsis(…) at the end of my text, is this do able with just using CSS?
For instance say I have the following HTML – If I want to limit myText
to just 20 characters(with spaces) how would I do that?
<div class="myDiv">
<p class="myText">HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets and scripting
languages such as JavaScript.</p>
</div>
3
Answers
The short answer is not without JS.
An approximation is if you know the font size and the user is not zooming, then you can do overflow hidden
There is a CSS ‘length value’ of ch.
I think the only way without Javascript is to use a monospace font and the CSS ch unit