I have a table column that needs to be limited to a certain width - say 100 pixels. At times the text in that column is wider than this and contains no spaces. For example:
a_really_long_string_of_text_like_this_with_no_line_breaks_makes_the_table_unhappy
I would like to calculate the width of text server-side and add an ellipsis after the correct number of characters. The problem is that I don't have data about the rendered size of the text.
For example, assuming the browser was Firefox 3 and the font was 12px Arial. What would be the width of the letter "a", the width of the letter "b", etc.?
Do you have data showing the pixel width of each character? Or a program to generate it?
I think a clever one-time javascript script could do the trick. But I don't want to spend time re-inventing the wheel if someone else has already done this. I am surely not the first person to come up against this problem.
A point (pt) is equal to 0.352778 millimeters, 0.0138889 inches, or 1.333 pixels. Because millimeters and inches are measurements of physical items, they are not ideal to use with computer or mobile based applications because they dont always represent the correct size because of differences in screen resolution.
When you set font-size on an element, the element certainly does not inherit font size. This is about the effect of the relative nature of the em unit.
How about overflow: scroll?
Ext JS has a module to do just that
TextMetrics Provides precise pixel measurements for blocks of text so that you can determine exactly how high and wide, in pixels, a given block of text will be.
I am sure that there are other libraries available out there that do it as well.
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