Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Honor Whitespace padding to display columns in fixed width <select>

I am trying to create the effect of columns in a dropdown by padding text with whitespace as in this example:

<select style="font-family: courier;">
<option value="1">[Aux1+1] [*]  [Aux1+1]              [@Tn=PP] </option>
<option value="2">[Main]   [*]  [Main Apples Oranges] [@Fu=$p] </option>
<option value="3">[Main]   [*]  [Next NP]             [@Fu=n]  </option>
<option value="4">[Main]   [Dr] [Main]                [@Ty=$p] </option>
</select>

According to this blog, it's possible.

The problem is the whitespace is contracted so that the columsn don't line up. SAme results in FF, IE6 and Chrome.

What am I missing?

like image 222
Laramie Avatar asked Dec 29 '22 16:12

Laramie


2 Answers

You'll need to use &nbsp; instead of just normal spaces.

For example, you would do this with your option:

<option value="2">[Main]&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;[Main Apples Oranges]&nbsp;[@Fu=$p] </option>
like image 181
patmortech Avatar answered Dec 31 '22 04:12

patmortech


Expanding on the answer by patmortech to render a ListItem in asp.net with &nbsp; instead of &amp;nbsp;

//Pad the columns
string spaceDecode = Server.HtmlDecode("&nbsp;");
for (int i = 0; i < ddl.Items.Count; i++)
{
    ListItem item = ddl.Items[i];
    item.Text = item .Text.Replace(" ", spaceDecode);
}
like image 27
Laramie Avatar answered Dec 31 '22 04:12

Laramie