Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a 'div' tag.For this i am binding some data like "Everyone here helps because they enjoy helping".

Now i have to show like "Everyone here...." in my html Grid(Bound in 'Div' tags)

Can we do it by adjusting the 'div' width? need some suggestions...

Thanks in advance,
Posted

1 solution

Adjusting the element size would be a bad idea. First, you won't be able to correctly estimate the size of some text in Javascript. Even if you have complete information of the font metrics and textual content and full power of programming and raw OS API (which you don't have access to in Javascript), this is a notoriously difficult problem, due to font hinting and other complications. And, after all, some code needs to add '…' (by the way, …, not three dots).

You really need to leave the element self-sizing, depending on the content, and dynamically change the content to show few first words and …. You can do it with Javascript. For this purpose, you would need to calculate shortened versions of the text and remember those values in the code (this is good to do with Javascript array, which works as the associative container, with O(1) complexity of the search). Then you need to handle hover events (for example; it could be something else, according to your design) to show full or shortened text. The size of the div will be automatically adjusted depending in its inner HTML and CSS (padding).

To handle such events, it's the best to use jQuery, for example: http://api.jquery.com/hover[^].

Calculation of shortened text can be done using the function split():
http://www.w3schools.com/jsref/jsref_split.asp[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com[^],
http://learn.jquery.com[^],
http://learn.jquery.com/using-jquery-core[^],
http://learn.jquery.com/about-jquery/how-jquery-works[^] (start from here).

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900