Cool Brain
Cool Brain

Reputation: 649

Show spaces in option tag

I want to arrange my list as following:

Subject         Chapter         MCQ     Duration(min)
Physics 1            10          40               40
Chemistry 1           9          30               30
Math 1               10          40               40
Biology 1            12          40               20

So, I tried following:

<div style="font-family: "Lucida Sans Unicode"">
    <?php
        include_once('funcs.php');
        $f = new funcs();
        $res = $f->get_ques(); 
        printf("%-'.20s", 'Subject');
        printf("%-'.20s", 'Chapter');
        printf("%-'.20s", 'Marks');
        printf("%-'.20s", 'Duration');
   ?>
   <br/>
   <select>
   <?php
       while( $q = mysql_fetch_array( $res ) ) {
           echo '<option>', printf("%-'-20s", $f->get_sub($q['q_id'])), printf("%-'.20s", $q['chapter']), printf("%-'.20s", $q['mcq']), printf("%-'.20s", $q['time']), '</option>';
       }
   ?>
   </select>
</div>

And my output is:

enter image description here

Lines are zigzag. I want these lines to be strict. I tried to use fixed length font but failed. And I should remove these dots . as well. Anyone please help me.

Upvotes: 4

Views: 105

Answers (3)

Vineet1982
Vineet1982

Reputation: 7918

As such thing with different types and fonts would not possible as each character width is different from each other. There is only One way to do things required by you. In Options use Monospaced Font Courier or any other Monospaced font. I know the Courier has the same width of all characters. Just Change the font name to courier and view the required think needed by you.

Use style sheet prove the id is select and option and describe css rules as:

 <select id=abc>
     <option id=abc> def </option>
 </select> 

and in css

 #abc {font-family:.......}. 

The will be resolved

Upvotes: 0

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

change this

echo '<option>', printf("%-'-20s", $f->get_sub($q['q_id'])), printf("%-'.20s", $q['chapter']), printf("%-'.20s", $q['mcq']), printf("%-'.20s", $q['time']), '</option>';

to

echo '<option>', printf("% /&nbsp20s", $f->get_sub($q['q_id'])), printf("% /&nbsp20s", $q['chapter']), printf("% /&nbsp20s", $q['mcq']), printf("% /&nbsp20s", $q['time']), '</option>';

use &nbsp for space.

Upvotes: 3

tuxnani
tuxnani

Reputation: 3864

You can use use &nbsp; for spaces not -.

Upvotes: 1

Related Questions