[TYPO3] finding length of menu text string in HMENU

Christopher Torgalson bedlamhotel at gmail.com
Wed Nov 22 20:03:22 CET 2006


Hi,

On 11/22/06, Syed S Rahman <syedsrahman at gmail.com> wrote:
> Syed S Rahman wrote:
> > Hi all,
> >
> > I am using a suckerfish css horizontal dropdown menu in my template. Is
> > it possible to add a style="width:xxx;" attribute to my wraps using
> > typoscript so that the menu fits well into the template.
> >
> > To be more clear here's the existing markup:
> >
> > <ul id="nav">
> >     <li><a href="#">Percoidei</a>
> >         <ul>
> >             <li><a href="#">Remoras</a></li>
> >             <li><a href="#">Tilefishes</a></li>
> >             <li><a href="#">Bluefishes</a></li>
> >             <li><a href="#">Tigerfishes</a></li>
> >         </ul>
> >     </li>
> >
> >     <li><a href="#">Anabantoidei</a>
> >         <ul>
> >             <li><a href="#">Climbing perches</a></li>
> >             <li><a href="#">Labyrinthfishes</a></li>
> >             <li><a href="#">Kissing gouramis</a></li>
> >             <li><a href="#">Pike-heads</a></li>
> >             <li><a href="#">Giant gouramis</a></li>
> >         </ul>
> >     </li>
> >     <!-- etc. -->
> > </ul>
> >
> > I want to add the style attribute to the all the first level li tags
> > (direct descendants of ul).
> >
> > Any help in this regard will be appreciated. Thanks in advance.
> >
> > Syed S. Rahman.
> > syedsrahman at gmail.com
> Hi,
>
> I am really sorry but I forgot to add one thing in my query. I want to
> add the style="width:xxx;" attribute based on the length of the string
> present inside the <li><a>string</a></li> tag, which is generated by the
> HMENU cObject.



How do you propose to find out the width (in pixels!) of a string on
the /server/ before the page is served?

TS provides configuration for php data, but php doesn't know anything
about rendering content--that's the client's job. The only way you can
find the width an object will be once it's rendered is to let the
browser render it and then determine its size with javascript (which
you could also use to dynamically set the width of your individual
menu items).

A better overall solution is probably to ensure that your design
contains enough flexibility that it doesn't break if a menu item wraps
on to a second line.


-- 
Christopher Torgalson



More information about the TYPO3-english mailing list