开发者

Maintaining white space in html select tag

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?


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));


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()).

http://us3.php.net/str_pad


Replace spaces with   HTML entity.


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...


Wrap it in the html "code" tag.


Replace the multiple spaces following each other with non breaking spaces:

 


Convert spaces to  ?

Try to use   (Non breaking space) is that what your looking for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜