CSS菜单突出显示不留在儿童悬停

时间:2014-05-09 17:27:57

标签: html css css3 user-interface

我正在尝试使用css创建一个分层菜单。我可以看到的问题是,当我进入第3个UL时,第二个UL失去了它的样式(白色字体颜色)。在我的CSS中我缺少的是将第二个UL保持为浅蓝色BG的白色字体,就像我使用顶级UL一样?

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

由于

Blanks out the 2nd layer menu item

<nav id="menu">
<ul>
    <li><a>Users</a></li>
    <li>
        <a>Applications</a>
        <ul>
            <li>
                <a>Application 1</a>
                <ul>
                    <li><a>Users</a></li>
                    <li><a>Roles</a></li>
                    <li><a>Groups</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>
</nav>

    nav {
    float: left;
    background: #142c56;
    color: #ffffff;
    height: 45px;
}

    nav ul li:hover > ul {
        display: block;
    }


nav ul {
    box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
    position: relative;
    display: inline-block;
    list-style: none;
    white-space: nowrap;
    margin-left: 20px;
    box-sizing: content-box;
}
    nav ul:after {
        content: ""; clear: both; display: block;
    }

    nav ul li {
        float: left;
    }
        nav ul li:hover {
            background: #425677;
            color: #ffffff;
        }

        nav ul li a {
            display: block;
            padding: 14px 33px;
            margin-top: 1px;
            cursor: pointer;
            text-decoration: none;
        }       

    nav ul ul {
        background: #ffffff;
        position: absolute; 
        top: 100%;
        margin-left: 0px;
        display: none;
    }
        nav ul ul li {
            float: none;
            position: relative;
        }
            nav ul ul li a {
                padding: 15px 40px;
                color: #425677;
                margin-top: 0px;
            }
                nav ul ul li a:hover {
                background: #425677;
                color: #ffffff;
                }

    nav ul ul ul {
        position: absolute; left: 100%; top:0;
    }

2 个答案:

答案 0 :(得分:1)

您可以将该笔的CSS中的第75行更改为nav ul li:hover > a - 该链接会覆盖文本的颜色,这就是您需要过度指定此内容的原因规则。

答案 1 :(得分:-1)

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
    font-family: "Segoe UI", Segoe, Tahoma, Verdana, Helvetica, Sans-Serif
}
ol, ul {
    list-style: none; 
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}


nav {
        float: left;
        background: #142c56;
        color: #ffffff;
        height: 45px;
    }

        nav ul li:hover > ul {
            display: block;
        }


    nav ul {
        box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
        position: relative;
        display: inline-block;
        list-style: none;
        white-space: nowrap;
        margin-left: 20px;
        box-sizing: content-box;
    }
        nav ul:after {
            content: ""; clear: both; display: block;
        }

        nav ul li {
            float: left;
        }
            nav ul li:hover {
                background: #425677;
                color: #ffffff;
            }

            nav ul li a {
                display: block;
                padding: 14px 33px;
                margin-top: 1px;
                cursor: pointer;
                text-decoration: none;
            }       

        nav ul ul {
            background: #ffffff;
            position: absolute; 
            top: 100%;
            margin-left: 0px;
            display: none;
        }
            nav ul ul li {
                float: none;
                position: relative;
            }
                nav ul ul li a {
                    padding: 15px 40px;
                    margin-top: 0px;
                }
                    nav ul ul li a:hover {
                    background: #ff2800;
                    color: #ffffff;
                    }

        nav ul ul ul {
            position: absolute; left: 100%; top:0;
        }

试试这段代码:)