如何在选择标签中创建分隔符?
New Window
New Tab
-----------
Save Page
------------
Exit
如何在选择标签中创建分隔符?
New Window
New Tab
-----------
Save Page
------------
Exit
当前回答
另一种方法是在选项上使用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
如果不想使用optgroup元素,可以将破折号放在option元素中,并为其指定disabled属性。它将是可见的,但灰色。
<option disabled>----------</option>
我选择有条件地交替颜色和背景。设置排序顺序,使用vue.js,我做了这样的事情:
<style>
.altgroup_1 {background:gray; color:white;}
.altgroup_2{background:white; color:black;}
</style>
<option :class = {
'altgroup_1': (country.sort_order > 25),
'altgroup_2': (country.sort_order > 50 }"
value="{{ country.iso_short }}">
{{ country.short_name }}
</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选择控件中添加水平线?
<option data-divider="true" disabled>______________</option>
你也可以做这个。这是很容易的,使分割线选择下拉列表。