Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

module to measure string in pixels

by Andre_br (Pilgrim)
on May 25, 2005 at 19:14 UTC ( [id://460425]=perlquestion: print w/replies, xml ) Need Help??

Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Hello folks,

Here´s the problem, I want to line up a drop-down select menu that was supposed to have two columns (if our friend Mr Html gave us this possibility). As he doesn´t, I´m trying to line up the first and second pseudo-columns with alterned   and spaces, like this:

<select name="myselect" class="form_s"> <option value="a" selected>this is a big text &nbsp; 1 match</option> <option value="b" selected>small txt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp +; &nbsp; &nbsp; &nbsp; 30 matches</option> </select>
Naturally, the options are generated by perl from an array, and, I thought, hey, no problem, it´s just a matter of counting the number of characters and inserting one space (or &nbsp;) for each one that it lacks to a defined lenght.

But the problem is that some letters occupy less space than others, so the pseudo-columns do not align.

Then, I thought if there is any way to measure the expected length in pixels with Perl. You guys know of any?

Thanks a lot, buddys

André

Replies are listed 'Best First'.
Re: module to measure string in pixels
by dws (Chancellor) on May 25, 2005 at 19:35 UTC

    I thought if there is any way to measure the expected length in pixels with Perl. You guys know of any?

    That information isn't available on the server side, since the server doesn't have knowledge of what fonts the user has installed on the client side, and browsers do font substitution if the requested font isn't available.

    What you could do is use CSS to specify a fixed-width font for the option text. Something like (untested):

    <style type="text/css"> #form_s option { font: "courier new", monospace; } </style>
    then you can line up your text by counting characters.

      dws ++! Very good.
      catch: user can/may have overiden your style sheet.
      bottom line: should work for most
Re: module to measure string in pixels
by suaveant (Parson) on May 25, 2005 at 21:05 UTC
    You could also create a drop down list of your own using a table and DHTML, but that is a whole other can of poisonous firebreathing exploding worms.

                    - Ant
                    - Some of my best work - (1 2 3)

      Hey folks,

      Thanks a lot for the replies. The monospace then it will be. Good solution, in fact.

      Thanks a lot

      André

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://460425]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-16 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found