You can get a similar result using the unit ch
, it would not be exactly by number of characters, but would be very close. This happens because the measure is made by the amount of 0
defined in the glyph that generates the source. Something similar to this f039
(used in FontAwesome) or so U+0030
.
'ch' Relative to width of the "0" (zero)
Font
Because it is measured by the glyph and not by the character itself, this measure can vary from source to source, that is, it may be that just by changing the font of the project the amount of characters displayed is different. >
Here is an example of the code:
p {
max-width: 15ch;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Example: link
Note that p
has a maximum width of 15ch
, which causes the line to break after the 15% 0
obtained in glyph analysis, the rest of the code only guarantees that this line break is not visible and that the 3 points are added at the end of the line. If you do not want this 3-point display, simply remove the text-overflow
property, but it may have strange behavior and break in the middle of the letter.
With the use of text-overflow, it is possible to break exactly in the character, giving a better presentation (at least in the ones I tested).
Now, if you want to break exactly in the 15th character regardless of font, etc. Only with CSS will not be possible.
I hope I have helped.