0

I am attempting to build a select box with options that require minor formatting and am running into issues.

an example of what I am looking for in an option text:

title      (some content)
title-2nd  (other content)

And while I have formatted the text in the option elements to look like the text above all my extra spaces seem to be truncated when it is rendered.

actual html:

<option value="1">1st Option       (0, 0, 0) </option>
<option value="5">Default Option   (0, 0, 0) </option>
<option value="6">Other            (0, 0, 0) </option></select>

Again, when rendered in HTML the spaces are gone and all the text is just aligned left and single spaced.

I know there are javascript replacements for the select, but would like to avoid if possible.

Is there a special char I can use (&nbsp; didn't work)

Thanks in advance. (Hope this made sense)

EDIT: So there have been a few mentioning using javascript components to replace the select, and I do know how that works but would like to avoid it.

Adding some screen shots to show the difference between what I am seeing in jsFiddle and codepen vs what I am seeing locally

enter image description here

markup

enter image description here

Again, any help would be greatly appreciated

QBM5
  • 2,778
  • 2
  • 17
  • 24

2 Answers2

2

Maybe try &#160; instead of &emsp;

Like this

Vincent G
  • 8,547
  • 1
  • 18
  • 36
1

form fields are notoriously difficult to style, especially elements like <select> and <option>.

MDN - Styling HTML forms

your idea to use a special character can work though. you can tabulate the options yourself using em spaces like so.

EDIT: too new to comment ^__^

did you define your character set in the header of your HTML?

try adding <meta charset="utf-8"> in your header. it's likely included in Codepen and JSFiddle. I'm thinking maybe your browser doesn't know your local copy wants to use Unicode characters.

  • I see that your solution is working in the code pen, but it is not working locally. I will add a screenshot to my original question to show what i mean – QBM5 Mar 08 '16 at 15:01