css

时间:2015-10-01 17:03:15

标签: javascript jquery html css css3

我想创建一个代码,我将鼠标悬停在菜单项中,并显示一个带有列表的子菜单...

这是我首先在CSS上的html 导航代码,然后是HTML代码......:

nav {
    background-color: #FFF;
    width: 960px;
    margin: 0 auto;
}

div.ajuste {
    clear: both;
}

nav ul {
    width: 95%;
    margin: 5px 5px 0 5px;
    padding: 10px 10px 10px 6px;
    height: 40px;
    line-height: 100%;
    background: #FFF;
   /* position:relative;
    z-index:999;
    overflow: hidden;*/
    float:left;
    list-style-type: none;
}

    nav li {
        margin-bottom: 10px;
        padding-right: 25px;
        float: left;
        /*position: relative;*/
        /*list-style: none;*/
    }

    nav a {
        color: #36E;
        font-weight: bold;
        text-decoration: none;
        /*margin-right: 6%;*/
        font-family: arial, sans-serif;
        font-style: normal;
        font-size: 15px;
        text-decoration: none;
        display: block;
        padding: 6px 20px 6px 20px;
        /*margin-bottom: 10px;*/
    }

    nav a:hover {
        color: #0505B4;
    }

    nav a.active {
        color: #1414D3;
    }

    ul.dropdown, ul.dropdown li, ul.dropdown ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    ul.dropdown {
        position: relative;
        z-index: 597;
        float: left;
    }

    ul.dropdown li {
        float: left;
        min-height: 1px;
        line-height: 1.3em;
        vertical-align: middle;
    }

    ul.dropdown li.hover, ul.dropdown li:hover {
        position: relative;
        z-index: 599;
    }

    ul.dropdown ul {
        visibility: hidden;
        position: absolute;
        top: 100%;
        left: 0;
        z-index: 598;
        width: 100%;
    }

    ul.dropdown ul li {
        float: none;
    }

    ul.dropdown ul ul {
        top: 1px;
        left: 99%;
    }

    ul.dropdown li:hover > ul {
        visibility: visible;
    }
 <nav>
            <ul id="menu_bar" class="dropdown">
	            <li><a href="#" class="active">Inicio</a></li>
	            <li><a href="#">Biografía</a></li>
	            <li class="submenu"><a href="#">Discografía</a></li>
                    <ul>
                        <li><a href="#">Innerspeaker</a></li>
                        <li><a href="#">Lorenism</a></li>
                        <li><a href="#">Currents</a></li>
                    </ul>
               </li>
         </ul>
        <div class="ajuste">
<nav>

当我将鼠标悬停时,我的失败发生...列表子菜单未显示... 我的代码有什么不好?

2 个答案:

答案 0 :(得分:2)

第二个UL,需要在LI标签内。

&#13;
&#13;
nav {
    background-color: #FFF;
    width: 960px;
    margin: 0 auto;
}

div.ajuste {
    clear: both;
}

nav ul {
    width: 95%;
    margin: 5px 5px 0 5px;
    padding: 10px 10px 10px 6px;
    height: 40px;
    line-height: 100%;
    background: #FFF;
   /* position:relative;
    z-index:999;
    overflow: hidden;*/
    float:left;
    list-style-type: none;
}

    nav li {
        margin-bottom: 10px;
        padding-right: 25px;
        float: left;
        /*position: relative;*/
        /*list-style: none;*/
    }

    nav a {
        color: #36E;
        font-weight: bold;
        text-decoration: none;
        /*margin-right: 6%;*/
        font-family: arial, sans-serif;
        font-style: normal;
        font-size: 15px;
        text-decoration: none;
        display: block;
        padding: 6px 20px 6px 20px;
        /*margin-bottom: 10px;*/
    }

    nav a:hover {
        color: #0505B4;
    }

    nav a.active {
        color: #1414D3;
    }

    ul.dropdown, ul.dropdown li, ul.dropdown ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    ul.dropdown {
        position: relative;
        z-index: 597;
        float: left;
    }

    ul.dropdown li {
        float: left;
        min-height: 1px;
        line-height: 1.3em;
        vertical-align: middle;
    }

    ul.dropdown li.hover, ul.dropdown li:hover {
        position: relative;
        z-index: 599;
    }

    ul.dropdown ul {
        visibility: hidden;
        position: absolute;
        top: 100%;
        left: 0;
        z-index: 598;
        width: 100%;
    }

    ul.dropdown ul li {
        float: none;
    }

    ul.dropdown ul ul {
        top: 1px;
        left: 99%;
    }

    ul.dropdown li:hover > ul {
        visibility: visible;
    }
&#13;
 <nav>
     <ul id="menu_bar" class="dropdown">
	   <li><a href="#" class="active">Inicio</a></li>
	   <li><a href="#">Biografía</a></li>
	   <li class="submenu">
	       <a href="#">Discografía</a>
               <ul>
                   <li><a href="#">Innerspeaker</a></li>
                   <li><a href="#">Lorenism</a></li>
                   <li><a href="#">Currents</a></li>
               </ul>
          </li>
    </ul>
<nav>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您有一个额外的li标记。摆脱它,它应该工作

<nav>
    <ul id="menu_bar" class="dropdown">
        <li><a href="#" class="active">Inicio</a>

        </li>
        <li><a href="#">Biografía</a>

        </li>
        <li class="submenu"><a href="#">Discografía</a>

            <ul>
                <li><a href="#">Innerspeaker</a>

                </li>
                <li><a href="#">Lorenism</a>

                </li>
                <li><a href="#">Currents</a>

                </li>
            </ul>
        </li>
    </ul>
    <div class="ajuste">
        <nav>