Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning part of a select option's text on the left and part on the right?

I have a select box and I need to have some of the options' text aligned to the left with the rest to the right, like this:

| option 1      0.5 |
| option 2      1.5 |

Is that possible? I thought about putting div's in the option, but in searching to see if that's allowed I ran across several places that said it wasn't.

Thanks for your help.

like image 692
Nate Avatar asked Sep 15 '12 20:09

Nate


People also ask

How do you align some text left and some right?

Align the text left or right Select the text that you want to align. On the Home tab, in the Paragraph group, click Align Left or Align Right .

How do I align text to both left and right margins?

On the Home tab, click the Paragraph group's dialog launcher and then click Tabs in the bottom-left corner. Enter 6.5 in the Tab stop position. Click Right in the Alignment section (Figure C). Click Set.

How do I align text left and right in Word?

Align a Paragraph To align left, press Ctrl + L. To align right, press Ctrl + R. To align center, press Ctrl + C. To justify, Ctrl + J.

Which alignment is used to align text between left and right of the cell?

Select the cells that have the text you want aligned. To horizontally align text, pick Align Text Left , Center , or Align Text Right .


1 Answers

The option element content is taken as plain text (no tags are recognized), so there is no direct way to do it. As a clumsy workaround, you can hand-format the options using a monospace font and use no-break spaces:

    <style>
    select, option { font-family: Consolas,  monospace; }
    </style>
    <select>
    <option>option 1          0.5
    <option>option 2          1.5
    <option>one more option 110.5
    </select>

(where the spaces inside the option elements are no-break spaces; use &nbsp; for them if you don’t know how to type no-break spaces in your authoring environment).

A completely different workaround, or approach, is the replace the select element by a set of checkboxes (or, depending on desired logic, radio buttons) and associated labels. You can then represent this data in a table and set suitable formatting on it:

    <table>
    <tr><td><input type=checkbox> <td>option 1 <td align=right>0.5
    <tr><td><input type=checkbox> <td>option 2<td align=right>1.5
    <tr><td><input type=checkbox> <td>one more option <td align=right>110.5
    </table>
like image 94
Jukka K. Korpela Avatar answered Sep 26 '22 03:09

Jukka K. Korpela