Working out size of strings made of varable width fonts.

7 views
Skip to first unread message

Ben Edwards

unread,
Sep 23, 2017, 9:52:07 AM9/23/17
to Ruby on Rails: Talk
I want to use this to put truncate stuff and put ... If a text string in too long.

I can work out how to do this in thery, with an array of chars and relative widths (for a specific font, in my case Helvitica) but can find details fo the widths anywhare.  Any ideas?


Hassan Schroeder

unread,
Sep 23, 2017, 11:30:00 AM9/23/17
to rubyonrails-talk
Yes: forget it.

The web is not print. You may specify 12pt Helvetica but what the
end user sees may be something else -- a different font, a different
size, different kerning, different line height, different word-spacing...

That's aside from the question of "too long" for what? To fit in a
container that's probably variable in size as well?

Seems unlikely to be time well spent :-)

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Walter Lee Davis

unread,
Sep 23, 2017, 11:34:15 AM9/23/17
to rubyonra...@googlegroups.com

> On Sep 23, 2017, at 9:52 AM, Ben Edwards <lo...@funkytwig.com> wrote:
>
> I want to use this to put truncate stuff and put ... If a text string in too long.


There is a CSS property for overflow, which will take the letterforms and specific characters into account. See more here: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow

Walter

Walter Lee Davis

unread,
Sep 23, 2017, 11:35:38 AM9/23/17
to rubyonra...@googlegroups.com
Sorry for the premature Send, I really meant this: https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow

This does the same thing as overflow but for runs of text, and puts an ellipsis at the end as you describe.

Walter

>
> Walter
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/850E964B-2CF8-4C6B-BA01-DB8A4970EC94%40wdstudio.com.
> For more options, visit https://groups.google.com/d/optout.

Hassan Schroeder

unread,
Sep 23, 2017, 11:41:30 AM9/23/17
to rubyonrails-talk
On Sat, Sep 23, 2017 at 8:35 AM, Walter Lee Davis <wa...@wdstudio.com> wrote:

> https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow
>
> This does the same thing as overflow but for runs of text, and puts an ellipsis at the end as you describe.

/me realizes how long it's been since I did *any* UI/CSS work... 🙄

Ben Edwards

unread,
Sep 23, 2017, 12:21:45 PM9/23/17
to Ruby on Rails: Talk
Thanks. Will have a look but it's CSS cards using UL tag and flux-box. If I had realised it would be a CSS question I would of posted elsewhere.
Reply all
Reply to author
Forward
0 new messages