Appending "..." after so many pixels in a string

This is a discussion on "Appending "..." after so many pixels in a string" within the Web Page Design section. This forum, and the thread "Appending "..." after so many pixels in a string are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 24th, 2008, 15:46
New Member
Join Date: Jan 2008
Location: Sydney
Age: 19
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Appending "..." after so many pixels in a string

Hi,
I have a table which has a fixed row length with many strings of many different lengths, which can only be on a single line.

Currently I use "<div style='overflow: hidden; width: 100%; white-space: nowrap;'>" in the row to hide the end of the string if it's too long to fit, but I want to add a "..." just before it gets cut off.

I know how to do this if the string is beyond a certain character length, but not pixel length which is what I'm after here.

Thanks
Reply With Quote

  #2 (permalink)  
Old Jan 24th, 2008, 16:05
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,662
Thanks: 0
Thanked 9 Times in 9 Posts
Re: Appending "..." after so many pixels in a string

Do you use anything like PHP? If you do, you could use strlen().
Reply With Quote
  #3 (permalink)  
Old Jan 24th, 2008, 16:18
New Member
Join Date: Jan 2008
Location: Sydney
Age: 19
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Appending "..." after so many pixels in a string

Thanks for the reply, and yeah I do use PHP but I sort of wanna steer away from using strlen because it gets the length in characters, not pixels.
The problem being a string with say 15 W's is a lot different pixel wise than 15 i's.
Reply With Quote
  #4 (permalink)  
Old Jan 24th, 2008, 16:23
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Appending "..." after so many pixels in a string

Hmmm ... but what it the cut-off is in the middle of that W or M ?

Will you only show 1/2 or 1/3 of said letter?

That's why it's string and not pixels
Reply With Quote
  #5 (permalink)  
Old Jan 24th, 2008, 16:29
New Member
Join Date: Jan 2008
Location: Sydney
Age: 19
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Appending "..." after so many pixels in a string

Well, currently with "<div style='overflow: hidden; width: 100%; white-space: nowrap;'>" it does that, and it doesn't look too strange, I also use a title attribute to show the full name.

I'm thinking it would require a bit of JavaScript work, which I'm pretty unfamiliar with. The only place I can remember this being done was on Web MSN's contact list, so if it's overly complicated, I'll just stick with what I have now
Reply With Quote
  #6 (permalink)  
Old Jan 24th, 2008, 16:37
JustinStudios's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: USA
Posts: 404
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Appending "..." after so many pixels in a string

If you are using width 100% you don't really have a good idea of what amount of pixels are being used, plus the browser size can be changed on the fly. I'd personally do a string check and if it is above a certain number of strings display the ... else don't. That's the only thing I can see that would work. Pixels are not going to work with percentages.
Reply With Quote
  #7 (permalink)  
Old Jan 24th, 2008, 16:56
New Member
Join Date: Jan 2008
Location: Sydney
Age: 19
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Appending "..." after so many pixels in a string

Ah, the row is at a fixed length (500px) but the 100% is just the <div> inside the row. There was a comment on the php.net strlen doc that hopefully will do what I want.

Thanks everyone!
Reply With Quote
  #8 (permalink)  
Old Jan 24th, 2008, 17:00
JustinStudios's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: USA
Posts: 404
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Appending "..." after so many pixels in a string

Cheers!

Well good to see that you found a solution.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a "tag" system to find relevant "related" pages MrQuestions PHP Forum 3 Mar 20th, 2008 23:06
[SOLVED] Show "Image" Depends On User "Status"? Monie Classic ASP 6 Oct 16th, 2007 01:22
? IS "meta name="robots" content="?" necessary in pages ? Love2Java Starting Out 6 Aug 8th, 2007 13:48
window.opener.document["nameForm"].getElementById("someid").value; doesnt work drpompeii JavaScript Forum 0 Feb 17th, 2007 23:09
<option value="yes" class="x"> problem in Firefox mameha1977 Web Page Design 1 Jun 21st, 2006 11:20


All times are GMT. The time now is 20:00.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43