CSS垂直下拉菜单,当鼠标悬停到其他菜单时,子菜单显示

时间:2015-11-18 15:49:48

标签: html css drop-down-menu hover

这样做的正确或最佳方式是什么?我无法解决它:3 当您将鼠标悬停在其他菜单上时,会显示成员子菜单 我的代码有什么问题?我无法弄清楚:3 你可以在链接中看到我的代码

http://codepen.io/anon/pen/MaxmvO

<html>
<head>
    <title>Dashboard</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>

    <header>
        <div class="logo"><a href="#">WORKOUT <span>FITNESS CENTER</span></a></div>
    </header>
    <div id="container">
        <nav>
            <ul>
                <li><a href="#">Walk-In</a></li>
                <li><a href="#">Members</a></li>
                    <ul>
                        <li><a href="#">List of Members</a>
                        <li><a href="#">Subscr</a></li>
                        <li><a href="#">asdasd</a></li>
                    </ul>
                </li>
                <li><a href="#">Sales</a></li>
                <li><a href="#">Inventory</a></li>
                <li><a href="#">Suppliers</a></li>
                <li><a href="#">Reports</a></li>
            </ul>
        </nav>

        <div id="content">
            SOME CONTENT YAY
        </div>
    </div>


</body>
</html>

CSS

 @import url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300italic,300);
*{
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Open Sans';
}

a{
    text-decoration: none;
}

header{
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #858585;
}

.logo {
    float: left;
    margin-top: 9px;
    margin-left: 15px;  
}

.logo a{
    font-size: 1.3em;
    color: #070807;

}
.logo a span{
    font-weight: 300;
    color: #1AC93A;
}

nav{
    width: 250px;
    height: calc(100% - 50px);
    background-color: #171717;
    float: left;
}

#content {
    width: :auto;
    margin-left: 250px;
    height: calc(100% - 50px);
    padding: 15px
}

nav li{
    list-style: none;

}

nav li a{
    color: #ccc;
    display: block;
    padding: 10px;
    font-size: 0.8em;
    border-bottom: 1px solid #0a0a0a;
    -webkit-transition: 0.2s;
    -moz-transition: 0.2s;
    -o-transition: 0.2s;
    transition: 0.2s;
}

nav li a:hover{
    background-color: #030303;
    color: #fff;
    padding-left: 80px;
}

nav ul ul {
    display: none;
}

nav ul:hover ul{
    display: block;
}

2 个答案:

答案 0 :(得分:0)

您需要定位特定元素,然后显示子菜单。我为此id添加了li,以便更容易定位并删除</li>,以便ul位于li#members内。

<li id="members"><a href="#">Members</a>
  <ul>
     <li><a href="#">List of Members</a></li>
      <li><a href="#">Subscr</a></li>
      <li><a href="#">asdasd</a></li>
  </ul>
</li>

nav #members:hover ul{
  display: block;
}

答案 1 :(得分:0)

试试这个http://codepen.io/anon/pen/gaEWJw

<强> HTML

        .file   "test.c"
    .LC0:
        .ascii "\n\0"
    .LC1:
        .ascii "\033[1;31m.\033[0m\0"   
    .LC2:
        .ascii "\033[1;31m#\033[0m\0"
    .LCtest0:
        .ascii "\033[1;32mdebug\033[0m\0"
    .LCtest1:
        .ascii "\033[1;31mdebug\033[0m\0"
    .LCtest2:
        .ascii "\033[1;34mdebug\033[0m\0"

        .def    main;   .scl    2;  .type   32; .endef
    main:
        /* initialisation du main */
        pushq   %rbp
        movq    %rsp, %rbp
        subq    $48, %rsp
        movl    %ecx, 16(%rbp) /* int argc */
        movq    %rdx, 24(%rbp) /* char **argv */
        movq    %r8, 32(%rbp) /* char **env */

        /* saut de ligne */
        /* write init */
        movl    $1, %r8d /* write size */
        movl    $1, %ecx /* sortie standart */
        leaq    .LC0(%rip), %rdx
        /* write */
        call    write

        /* debut du code */
        movl    $-1, -8(%rbp) /* y = -1 */
        jmp .Loop_1_condition

    .Loop_1_body:
        movl    $-1, -4(%rbp)
        jmp .Loop_2_condition

    .Loop_2_body:
        /* affiche le charactere */
        movl    $1, %r8d
        movl    $1, %ecx
        call    write

    .Loop_2_condition:
        addl    $1, -4(%rbp) /* x = -1 */
        movl    -8(%rbp), %eax
        cltq
        addq    32(%rbp), %rax
        movq    (%rax), %rax
        movq    %rax, %rdx
        movl    -4(%rbp), %eax
        cltq
        addq    %rdx, %rax
        movq    %rax, %rdx
        movq    (%rax), %rax
        cmpq    $0, %rax
        jne .Loop_2_body

        /* saut de ligne */
        movl    $1, %r8d /* write size */
        movl    $1, %ecx /* sortie standart */
        leaq    .LC0(%rip), %rdx
        call    write

    .Loop_1_condition:
        addl    $1, -8(%rbp) /* ++y */
        movl    -8(%rbp), %eax
        cltq /* passe eax en 64bits */
        addq    32(%rbp), %rax
        movq    (%rax), %rax
        cmpq    $0, %rax
        jne .Loop_1_body

        movl    $1, %r8d /* write size */
        movl    $1, %ecx /* sortie standart */
        leaq    .LC0(%rip), %rdx
        call    write

        /* fin du programme */
        movl    $0, %eax /* return (0) */
        addq    $48, %rsp
        popq    %rbp
        ret
        .def    write;  .scl    2;  .type   32; .endef

<强> CSS

 <nav>
    <ul>
        <li><a href="#">Walk-In</a></li>
        <li><a href="#">Members</a></li>
        <li><a href="#">List of Members</a>             
            <ul>
                <li><a href="#">Subscr</a></li>
                <li><a href="#">asdasd</a></li>
            </ul>       
        </li>
        <li><a href="#">Sales</a></li>
        <li><a href="#">Inventory</a></li>
        <li><a href="#">Suppliers</a></li>
        <li><a href="#">Reports</a></li>
    </ul>
 </nav>