0

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

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

展览应该有一个子菜单,其中包含两个链接 Current 和 Previous。

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; 
  }
4

1 回答 1

0

两个小错误:

  1. 您拥有绝对 .submenu的定位- 所以它就在您的显示器旁边的某个地方。将其从 to和 number to更改为right900pxrightleft900px120px
  2. .submenu 中的列表项应该显示inline-blockinline

JSFiddle:http: //jsfiddle.net/kn4Jx/4/

于 2013-06-30T08:08:41.057 回答