如何在选择标签中创建分隔符?
New Window
New Tab
-----------
Save Page
------------
Exit
如何在选择标签中创建分隔符?
New Window
New Tab
-----------
Save Page
------------
Exit
当前回答
你可以用em破折号" - "。每个字符之间没有可见的空格。(某些字体!) 在HTML中:
<option value="—————————————" disabled>—————————————</option>
或者在XHTML中:
<option value="—————————————" disabled="disabled">—————————————</option>
其他回答
另一种方法是在选项上使用css1x1背景图像,这似乎只适用于firefox,并有一个“----”后退
<option value="" disabled="disabled" class="SelectSeparator">----</option>
.SelectSeparator
{
background-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==);
color:black;
background-repeat:repeat-x;
background-position:50% 50%;
background-attachment:scroll;
}
http://jsfiddle.net/yNecQ/6/
或者使用javascript (jquery):
-hide the select element and
-show a div which can be completely styled and
-reflect the div state onto the select for the form submit
http://tutorialzine.com/2010/11/better-select-jquery-css3/
另请参阅 如何在html选择控件中添加水平线?
这将解决你的问题:
<选择> < optgroup > <选项>新窗口> < /选项 <选项>新选项卡> < /选项 < / optgroup > < optgroup标签 ="_________"> <选项>保存页面> < /选项 < / optgroup > < optgroup标签 ="_________"> <选项> < /退出选项> < / optgroup > < /选择>
Try:
<optgroup label="----------"></optgroup>
禁用选项方法看起来是最好的,也得到了最好的支持。我还包含了一个使用optgroup的示例。
Optgroup(这种方式有点糟糕):
选择< > < optgroup > <选项第一< - >选项> < / optgroup > < optgroup标签 ="_________"> <选项第二< - >选项> <第三选项> < /选项> < / optgroup > 选择< - >
禁用选项(更好一点):
<选择> <选项>第一次> < /选项 <选项禁用 >_________</ 选项> <选项>第二> < /选项 <选项>第三> < /选项 < /选择>
如果你想要更花哨,可以使用水平unicode方框绘图字符。 (最佳选择!)
选择< > <选项第一< - >选项> <选项残疾人>──────────< /选项> <选项第二< - >选项> <第三选项> < /选项> 选择< - >
http://jsfiddle.net/JFDgH/2/
这个总是最好的。
<option>First</option>
<option disabled>_________</option>
<option>Second</option>
<option>Third</option>