下拉菜单文本显示在背景之前

时间:2014-01-17 20:07:42

标签: html css css3 drop-down-menu

所以我用css3过渡制作了一个带有下拉效果的菜单,但我的问题是你可以在背景显示之前看到文字,当然这个想法不是在背景之前看到文字。 / p>

我做了一个j sfiddle

HTML:

<nav>
    <ul>
        <li>Home</li>
        <li>Parrent Link
            <ul>
                <li>Child Link</li>
                <li>Child Link</li>
                <li>Parrent Link
                    <ul>
                        <li>Child Link</li>
                        <li>Child Link</li>
                        <li>Child Link</li>
                        <li>Child Link</li>
                        <li>Child Link</li>
                    </ul>
                </li>
            </ul>
        </li>
        <li>About</li>
        <li>Contact</li>
    </ul>
</nav>

CSS:

    nav {
        position: fixed;
        top: 0;
        width: 100%;
        height: 50px;
        background: #30a0ff;
        z-index: 2;
        box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
}

nav > ul {
        position: relative;
    margin: 0 auto;
    padding: 0;
    width: 100%;
    list-style: none;
    text-align: center;
}

nav > ul > li {
    position: relative; 
    display: inline;
    padding: 12px 20px;
    line-height: 50px;
    font-size: 22px;
    color: #fff;
    cursor: pointer;
}

nav > ul > li:last-child {
    margin: 0 -20px 0 0;
}

nav ul li {
    -webkit-transition: all 0.2s ease-in-out;
    -moz-transition: all 0.2s ease-in-out;
    -ms-transition: all 0.2s ease-in-out;
    -o-transition: all 0.2s ease-in-out;
    transition: all 0.2s ease-in-out;
}

nav ul li:hover {
    background-color: #0f71c4;
}

nav > ul > li > ul {
    position: absolute;
    top: 50px;
    left: 0;
    height: 0;
    padding: 0;
    list-style: none;
    line-height: 20px;
    font-size: 17px;
    background-color: #30a0ff;
    overflow: hidden;
}

nav > ul > li:hover > ul {
    min-height: 110px;
    overflow: visible;
}

nav > ul > li > ul > li:first-child {
    padding: 15px 20px 5px 20px;
}

nav > ul > li > ul > li:last-child {
    padding: 5px 20px 15px 20px;
}

nav > ul > li > ul > li {
    position: relative;
    padding: 5px 20px;
    min-width: 150px;
    text-align: left;
}

nav ul li ul {
    box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -ms-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}

nav > ul > li > ul > li > ul {
    position: absolute;
    left: 190px;
    top: 0;
    padding: 0;
    width: 0;
    list-style: none;
    font-size: 16px;
    background-color: #30a0ff;
    overflow: hidden;
}

nav > ul > li > ul > li:hover > ul {
    min-width: 150px;
}

nav > ul > li > ul > li > ul > li {
    position: relative;
    padding: 5px 20px;
    min-width: 150px;
}

nav > ul > li > ul > li > ul > li:first-child {
    padding: 15px 20px 5px 20px;
}

nav > ul > li > ul > li > ul > li:last-child {
    padding: 5px 20px 15px 20px;
}

2 个答案:

答案 0 :(得分:2)

我刚刚将不透明度添加到现有的css:

js小提琴:

<强> http://jsfiddle.net/r9Dyq/2/

<强>的CSS:

nav > ul > li > ul {
    position: absolute;
    top: 50px;
    left: 0;
    height: 0;
    padding: 0;
    list-style: none;
    line-height: 20px;
    font-size: 17px;
    background-color: #30a0ff;
    overflow: hidden;
    opacity:0; /*newly added */
}

nav > ul > li:hover > ul {
    min-height: 110px;
    overflow: visible;
    opacity:1; /*newly added */
}

答案 1 :(得分:0)

只是不要更改overflow属性:

nav > ul > li:hover > ul {
  min-height: 110px;
  /*overflow: visible; Remove this*/
}

选中此http://jsfiddle.net/r9Dyq/1/