Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Q: Retrieve length (in pixels) of rendered string?? >Thread Next - Re: Q: Retrieve length (in pixels) of rendered string?? Re: Q: Retrieve length (in pixels) of rendered string??To: NULL Date: 12/10/2005 5:28:00 PM On Sat, 10 Dec 2005 10:25:16 +0800, "Jerry D. Turner" <f-off@s...> wrote: > >"Neil Smith [MVP Digital Media]" <neil@n...> wrote in message >news:8jajp1ds9hvq6sfb4ijsd7j5c1sn52n3hr@4...... >> On Fri, 9 Dec 2005 09:34:56 +0800, "Jerry D. Turner" >> <f-off@s...> wrote: >> >>>Is there a way in msxsl to retrieve the length, in pixels, of a string? >>>Say, for example, the text of a marquee object? I'd like to find out out >>>long a string is in pixels. >>> >>>Is this possible? >> >> No, it isn't. XSLT is entirely independent of any resultant display of >> output, you'd need to look at CSS and Javascript for that. >> >> Cheers - Neil > >Ah, ok. I gotcha, Neil. This stuff is starting to sink in (old dog and new >tricks and all that.) > >Well, in JS, is there something that will determine the rendered length of a >string? Although, I guess that's a bit off-topic for this forum, eh? Not really javascript even without a lot of ugly hackery : You have to consider how HTML works - if you insert a paragraph or DIV for example, and give it a style="border: 1px solid red" you can see the content (text) and also that the container fills the browser window to 100% width by default. So in that case, your content width is (whatever the width of the browser window is) : You can check this by asking for the clientWidth or scrollWidth properties. Also, you have to consider that using proportional fonts (arial, verdana, pretty much anything except courier) then the character width will vary, eg an 'i' is much narrower than a 'm' for example. The only way to fix those widths is with a fixed width font (eg courier in your CSS) or to use a <pre /> element which applies fixed width fonts by default in all browsers (not necessarily the same font though, so the width of the container could *still* vary ;-) However I think whatever your intention is, you're probably approaching this from the wrong angle. You're starting with a solution and want to know how to make that solution, without proposing what your actual problem is. I'll try to read between the lines : Why is it you need to determine the number of pixels of a marquee ? Would it help to know for example that you can use CSS overflow properties to fix the width of an item and clip the contained text ? For example : <html> <head> <style type="text/css"> p { border: 1px solid red; width: 200px; height: 18px; overflow: hidden; } </style> </head> <body> <p id="test">this is a test to see how wide my client paragraph will go</p> <p id="test2">this is a short paragraph</p> </body> That will give you 2 paragraphs which fit in a defined space, and the rightmost words of the longer paragraph are clipped from view by the browser (actually it splits the string at a space or soft-hyphen, and won't display words which don't fit in the bounding box). http://www.w3.org/TR/CSS21/visufx.html#overflow So in general, stick to exploiting the browser's rendering capabilties along with CSS and you'll probably make your life much simpler. There are lots of decent examples of what you can do with CSS+Javascript on Quirksmode among many websites : http://www.quirksmode.org/js/bilingual.html http://www.alistapart.com/articles/elastic/ If you're in any doubt about the capabilties of CSS, then http://www.csszengarden.com/ is always worth a weekly visit ;-) HTH Cheers - Neil | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
