如何在选择标签中创建分隔符?
New Window
New Tab
-----------
Save Page
------------
Exit
如何在选择标签中创建分隔符?
New Window
New Tab
-----------
Save Page
------------
Exit
当前回答
<option data-divider="true" disabled>______________</option>
你也可以做这个。这是很容易的,使分割线选择下拉列表。
其他回答
如果不想使用optgroup元素,可以将破折号放在option元素中,并为其指定disabled属性。它将是可见的,但灰色。
<option disabled>----------</option>
Try:
<optgroup label="----------"></optgroup>
以Jasneet的回答为基础
将禁用选项的背景设置为灰色(Jasneet) 在上面和下面添加禁用选项以填充分隔符
基本上,使用三个禁用选项来创建一个自然样式的分隔符。我选择了一条非常细的灰色线0.1px,垫高0.25em,因为我认为这样的组合看起来最自然:
<select>
<option :value="item1">Item 1</option>
<option disabled style="font-size: 0.25em;"></option>
<option disabled style="background: #c9c9c9; font-size: 0.1px;"></option>
<option disabled style="font-size: 0.25em;"></option>
<option :value="item2">Item 2</option>
</select>
这将解决你的问题:
<选择> < optgroup > <选项>新窗口> < /选项 <选项>新选项卡> < /选项 < / optgroup > < optgroup标签 ="_________"> <选项>保存页面> < /选项 < / optgroup > < optgroup标签 ="_________"> <选项> < /退出选项> < / 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选择控件中添加水平线?