具有水平子菜单和半透明带的CSS垂直导航菜单

时间:2013-06-30 07:40:22

标签: javascript jquery css navigation

我无法让我的子菜单与其父级保持/显示在同一行。我希望它位于通过鼠标悬停显示的透明带内。我是新手,任何建议都非常感谢。

Jsfiddle:http://jsfiddle.net/kn4Jx/

展览应该有一个子菜单,其中有两个链接当前和上一个。

HTML:

<div>
  <ul id="mainmenu">
    <li id="liHome">
      <a href="#item-x1y1" class="maintextcolour" rel="none" id="Home">INFO</a>
    </li>
    <li id="liServices" class="active">
      <a href="#item-x1y2" class="maintextcolour" rel="SubMenuY2"             id="Services">EXHIBITIONS</a>
    <ul id="SubMenuY2" class="submenu">
     <li><a href="#" class="maintextcolour">CURRENT</a></li>
     <li><a href="#" class="maintextcolour">PREVIOUS</a></li>
    </ul> 
    </li>
    <li id="liEnvironment">
      <a href="#item-x1y3" class="maintextcolour" rel="none" id="Environment">CV</a>
    </li> 
    <li id="liCareer">
      <a href="#item-x1y4" class="maintextcolour" rel="none" id="Career">NEWS</a>
    </li>
    <li id="liContact">
      <a href="#item-x1y5" class="maintextcolour" rel="none" id="Contact">MORE</a>
    </li>
    </ul
</div>

和css:

  body 
  {
   background-color:#06F;background-size: 100%;
   background-repeat:no-repeat;
  }

  #mainmenu
  {
   margin: 0;
   padding: 0; 
   list-style-type: none;
   position:relative;
   }

   #mainmenu li 
   {
    clear: left;
    position:relative;
   }

   #mainmenu a 
   {
    display: block;
    overflow: hidden;
    float: left;
    width:100%;
    position:relative;   
   }

    #mainmenu a:hover
   {   
    background-position: 0 0;   
    background-color:clear;   
    background-color:rgba(255,255,255,0.5);   
    width:100%;
   }

   #mainmenu li.active a 
   {   
    background-position: 0 0;   
    background-color:clear;
    width:100%;
   }

   .submenu 
   {   
    list-style-type: none;    
    float: left;   display: none;  
    position:absolute;   
    right:900px;   
    top:0px;
   }

   #mainmenu li a:hover+.submenu, .submenu:hover 
   {  
    display:inline-block;
   } 

  .submenu li 
  {
   display: inline;    
   clear: none !important;
  }

  .submenu li a 
  {   
   float: right;   
   margin-left: 10px;
  }

  .maintextcolour 
  {     
   font-family: Arial, Helvetica, sans-serif;
   font-size: 24px;     
   color:#FFF;  
   text-decoration: none; 
  }

  .maintextcolour:hover 
  {     
   font-family: Arial, Helvetica, sans-serif;
   font-size: 24px;     
   color:#0FF;  
   text-decoration: none; 
  }

1 个答案:

答案 0 :(得分:0)

两个小错误:

  1. 您的.submenu绝对定位于right 900px - 所以它就在你的显示器旁边。改变它 rightleft900px120px
  2. .submenu中的列表项应显示为inline-block而不是inline
  3. JSFiddle:http://jsfiddle.net/kn4Jx/4/