如何在选择标签中创建分隔符?

New Window
New Tab
-----------
Save Page
------------
Exit

当前回答

我把@Laurence Gonsalves的评论变成了一个答案,因为它是唯一一个在语义上起作用的,看起来不像一个黑客。

试着把这个添加到你的样式表中:

optgroup + optgroup { border-top: 1px solid black } 

比一堆破折号好看多了。

其他回答

Try:

<optgroup label="----------"></optgroup>

另一种方法是在选项上使用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选择控件中添加水平线?

如果只支持webkit,可以使用<hr>来创建真正的分隔符。

http://code.google.com/p/chromium/issues/detail?id=99534

我把@Laurence Gonsalves的评论变成了一个答案,因为它是唯一一个在语义上起作用的,看起来不像一个黑客。

试着把这个添加到你的样式表中:

optgroup + optgroup { border-top: 1px solid black } 

比一堆破折号好看多了。

这个总是最好的。

<option>First</option>
<option disabled>_________</option>
<option>Second</option>
<option>Third</option>