带选择选项的多级导航列表

时间:2013-06-12 05:53:47

标签: html css css3

我正在使用“select”“option”和“optgroup”创建一个嵌套列表... 这是我的代码

HTML

<div class="menu-2_small">
        <form name="nav-2">
       <select name="SelectURL" onchange="document.location.href=document.nav-2.SelectURL.options[document.nav-2.SelectURL.selectedIndex].value">
        <option value="#">Inspiration</option>
        <option value="#">Coding</option>
        <option id="show-further-option" value="#">Freebies
            <optgroup id="further-option">
            <option value="#">Textures</option>
            <option value="#">Fonts</option>
            <option value="#">Brushes</option>
            <option value="#">Vectors</option>
            <option value="#">Icons</option>
            </optgroup>
        </option>
        <option value="#">Design</option>
        <option value="#">Tutorials</option>
        <option value="#">Technology</option>
      </select>
    </form>
  </div>

和CSS

 .menu-2_small{
display:block;
width:100%;
height:35px;
background-image:url(imgs/link-bg-small.jpg);
background-repeat:no-repeat;
background-size:100% 100%;
}
 .menu-2_small select{
width:70%;
background-image:url(imgs/link-bg-small.jpg);
color:white;
font-size:0.70em;
margin:6px 0 0 1%;
cursor:pointer;


}

 .menu-2_small select option{background-image:url(imgs/link-bg-small.jpg);background-repeat:no-repeat;}
 .menu-2_small select option:hover{font-weight:bold;}
 optgroup{display:none;}
 option #show-further-option:hover optgroup{display:block;}

现在的问题是,当我将鼠标悬停在id为“show-further-option”的选项上时,无论我尝试什么,都不会显示optgroup ... 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

使用'label'属性显示optgroup名称。

<option id="show-further-option" value="#">Freebies
   <optgroup id="further-option" label="further-option">
       <option value="#">Textures</option>
       ....