Reputation: 413
I have a list of strings that I would like to display in a HTML select object. The strings look something like :
id - name - description
I would like the fields to align however. In PHP I'm using
sprintf ("%4s%10s%20s", $id, $name, $description);
which works fine. The problem is the multiple spaces is compacted to 1 space in the select list. I tried using the pre and white-space CSS properties of the select box, but it has no effect. Any suggestions?
Upvotes: 3
Views: 3644
Reputation: 6097
you have to use
instead, they are non-breaking spaces so it won't collapse.
You could do:
str_replace(" ", " ", sprintf("%4s%10s%20s", $id, $name, $description));
Upvotes: 4
Reputation: 45002
Convert spaces to
?
Try to use
(Non breaking space) is that what your looking for?
Upvotes: 0
Reputation: 32119
Replace the multiple spaces following each other with non breaking spaces:
Upvotes: 0
Reputation: 50225
You may have to replace the spaces with
to make this work correctly; though part of me thinks there's a much better to do this but my HTML-fu is weak...
Upvotes: 0
Reputation: 30394
Use CSS to set the font of the options to a monospaced font. Use
instead of spaces (you can use str_pad() instead of sprintf()).
Upvotes: 3