Javascript 在选择选项中对齐两个单词

Javascript 在选择选项中对齐两个单词,javascript,html,css,html-select,Javascript,Html,Css,Html Select,我有以下选择: <select name="mySelect"> <option value="1">hello [test]</option> <option value="2">hello2 [test2]</option> <option value="3">hello33 [test33]</option> <option value="4">hel [hel]<

我有以下选择:

<select name="mySelect">
   <option value="1">hello [test]</option>
   <option value="2">hello2 [test2]</option>
   <option value="3">hello33 [test33]</option>
   <option value="4">hel [hel]</option>
</select>

我尝试用JavaScript添加空格,但它们不可见。(上面是空格字符)

唯一的方法是首先设置
选择
元素以使用单空格字体(即字符宽度相同的字体),然后用
填充元素:

选择{
字体系列:monospace;
}

你好[测试]
hello2[test2]
hello33[test33]
赫尔[赫尔]

您可以使用
。字体也应该是单间距的。在css中设置此项。再次使用,它们没有正确对齐。。。虽然添加了空格。所以
hello[test]
不能正常工作吗?屏幕截图或小提琴会很好。我能不能保留我目前使用的字体?有没有一个解决方案是添加任何跨度并左右对齐?@sstauross我不知道,除非您当前使用的字体是monospace本身。不能在
选项
元素中添加HTML标记。正如我在回答的最后所写的,我能想到的唯一其他选择是用JavaScript控制的结构替换
select
元素,该结构似乎可以做同样的事情——尽管这可能会让您在跨浏览器和移动设备兼容性方面遇到很多问题。
hello____[test]

hello2___[test2]

hello33__[test33]

hel_____ [hel]