css下拉菜单阻止父菜单

时间:2014-02-16 04:05:15

标签: html css drop-down-menu

这是我第一次尝试构建一个合适的水平菜单而且我遇到了一些问题。当我将鼠标悬停在子菜单上时,其子菜单会覆盖它。在Chrome,Firefox和IE中测试过,都有同样的问题。我一直在寻找解决方案,所以任何帮助将不胜感激。继承菜单html

    <li><a>Courses</a>
 <ul>
  <li><a>RII31813</a>
   <ul>
    <li><a>Student Information</a></li>
    <li><a>BSBWHS301A Maintain workplace saftey</a></li>
    <li><a>RIIBEF301D Run on-site operations</a></li>
    <li><a>RIICOM201D Communicate in the workplace</a></li>
    <li><a>RIINHB301D Set up and prepare for drilling operations</a></li>
    <li><a>RIIRIS301D Apply risk management processes</a></li>
    <li><a>RIISAM209D Carry out operational maintenance</a></li>
    <li><a>MSAPMSUP172A Identify and minimise environmental hazards</a></li>
    <li><a>AEDEL301A Provide work skill instruction</a></li>
    <li><a>RIINHB307D Conduct conventional core drilling</a></li>
    <li><a>RIINHB308D Conduct wireline core drilling</a></li>
    <li><a>RIINHB324D Carry out grouting or cementing operations</a></li>
    <li><a>RIINHB208D Assist diamond core drilling</a></li>
    <li><a>RIIQUA201D Maintain and monitor site quality standards</a></li>
    <li><a>RIIVEH305D Operate and maintain a four wheel drive vehicle</a></li>
   </ul>
  </li>
 </ul>
</li>

然后是菜单CSS:

#menu ul {
    margin: 0px 0 0 0;
    _margin: 0; /*IE6 only*/
    opacity: 0;
    visibility: hidden;
    position: absolute;
    top: 38px;
    left: 0;
    z-index: 1;    
    background: #444;   
    background: linear-gradient(#444, #111);
    box-shadow: 0 -1px 0 rgba(255,255,255,.3);  
    border-radius: 3px;
    transition: all .2s ease-in-out;  
}

#menu li:hover > ul {
    opacity: 1;
    visibility: visible;
    margin-left: 0;
}

#menu ul ul {
    top: 0;
    left: auto;
    float:right;
    margin: 0 0 0 20px;
    _margin: 0; /*IE6 only*/
    box-shadow: -1px 0 0 rgba(255,255,255,.3);      
}

#menu ul li {
    float: none;
    display: block;
    border: 0;
    _line-height: 0; /*IE6 only*/
    box-shadow: 0 1px 0 #111, 0 2px 0 #666;
}

#menu ul li:last-child {   
    box-shadow: none;    
}

#menu ul a {    
    padding: 10px;
    width:auto;
    _height: 10px; /*IE6 only*/
    display: block;
    white-space: nowrap;
    float: none;
    text-transform: none;
}

#menu ul a:hover {
    background-color: #0186ba;
    background-image: linear-gradient(#04acec, #0186ba);
}

#menu ul li:first-child > a {
    border-radius: 3px 3px 0 0;
}

#menu ul li:first-child > a:after {
    content: '';
    position:absolute;
    left: 40px;
    top: -6px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #444;
}

#menu ul ul li:first-child a:after {
    left: -6px;
    top: 50%;
    margin-top: -6px;
    border-left: 0; 
    border-bottom: 6px solid transparent;
    border-top: 6px solid transparent;
    border-right: 6px solid #3b3b3b;
}

#menu ul li:first-child a:hover:after {
    border-bottom-color: #04acec; 
}

#menu ul ul li:first-child a:hover:after {
    border-right-color: #0299d3; 
    border-bottom-color: transparent;   
}

#menu ul li:last-child > a {
    border-radius: 0 0 3px 3px;
}

任何帮助都是恭喜的,谢谢

1 个答案:

答案 0 :(得分:0)

注意:我不知道原始HTML代码,我认为这可能是正确的HTML并继续使用

<强> HTML:

  <ul id="menu">
    <li><a>Courses</a>
        <ul>
        <li><a>RII31813</a>
        <ul>
            <li><a>Student Information</a></li>
            <li><a>BSBWHS301A Maintain workplace saftey</a></li>
            <li><a>RIIBEF301D Run on-site operations</a></li>
            <li><a>RIICOM201D Communicate in the workplace</a></li>
            <li><a>RIINHB301D Set up and prepare for drilling operations</a></li>
            <li><a>RIIRIS301D Apply risk management processes</a></li>
            <li><a>RIISAM209D Carry out operational maintenance</a></li>
            <li><a>MSAPMSUP172A Identify and minimise environmental hazards</a></li>
            <li><a>AEDEL301A Provide work skill instruction</a></li>
            <li><a>RIINHB307D Conduct conventional core drilling</a></li>
            <li><a>RIINHB308D Conduct wireline core drilling</a></li>
            <li><a>RIINHB324D Carry out grouting or cementing operations</a></li>
            <li><a>RIINHB208D Assist diamond core drilling</a></li>
            <li><a>RIIQUA201D Maintain and monitor site quality standards</a></li>
            <li><a>RIIVEH305D Operate and maintain a four wheel drive vehicle</a></li>
        </ul>
    </li>
 </ul>

<强> CSS:

我改变了内部<ul>

的位置
#menu ul ul {
    top: 0;
    left: 120px;
    float:right;
    margin: 0 0 0 20px;
    _margin: 0; /*IE6 only*/
    box-shadow: -1px 0 0 rgba(255,255,255,.3);      
}

它的工作正常:JSFIDDLE DEMO