-1

嘿,我想有一个相同风格的下拉子菜单,我知道这很简单,但我对制作网站还是新手,我自己无法弄清楚。

这是我的 HTML 文件:

<nav>
        <ul>
            <li><a href="./index.html"><span class ="s2">Startpagina</span></a></li>
            <li><a href="./aanwinsten.html">Aanwinsten</a></li>
            <li><a href="./catalogus.html">Catalogus</a></li>
                <ul class="sub">
                    <li><a href="#">Pages</a></li>
                    <li><a href="#">Archives</a></li>
                    <li><a href="#">New Posts</a></li>
                </ul>
            <li><a href="./uitlening.html">Uitlening</a></li>
            <li><a href="./reservatie.html">Reservatie</a></li>
            <li><a href="./suggestie.html">Suggestie</a></li>
            <li><a href="./contact.html">Contact</a></li>
        </ul>
    </nav>

这是我的 CSS 文件:

  nav li
{
    display: inline;
    padding-right: 20px;

}
nav {
    text-align: center;
    margin: -20px 0px 0px 0px;

}
nav ul{
    background-color: rgba(126, 4, 0, 0.79);
    border: 1px solid black;


}
nav ul li{
    display: inline;

}
nav ul li a{
    padding-left: 1em;
    padding-right: 1em;
    font-size: 12px;
    font-family: Arial, Helvetica, sans-serif;
    text-decoration: none;
    color: lightgray;
}
nav ul li a:hover{
    color: #999999;

}

编辑:我编辑了 /li 问题并将其添加到我的 CSS 中:

nav ul ul{display: none; position: relative;}
nav li ul li{float:none;display: inline-block; }
nav ul li:hover ul  {display: inline-block;}

当我悬停在它上面时,它给出了这个:http: //gyazo.com/e095151ebf644b4b44c7556193328163

4

2 回答 2

1

您太早关闭了li将保留子菜单的选项。ul

尝试使用这个:

<nav>
        <ul>
            <li><a href="./index.html"><span class ="s2">Startpagina</span></a></li>
            <li><a href="./aanwinsten.html">Aanwinsten</a></li>
            <li><a href="./catalogus.html">Catalogus</a>
                <ul class="sub">
                    <li><a href="#">Pages</a></li>
                    <li><a href="#">Archives</a></li>
                    <li><a href="#">New Posts</a></li>
                </ul>
            </li> **<! - See the difference?-->**
            <li><a href="./uitlening.html">Uitlening</a></li>
            <li><a href="./reservatie.html">Reservatie</a></li>
            <li><a href="./suggestie.html">Suggestie</a></li>
            <li><a href="./contact.html">Contact</a></li>
        </ul>
    </nav>

JSFiddle

于 2013-10-23T15:34:27.757 回答
1

问题出在这里:

    <li><a href="./catalogus.html">Catalogus</a></li>
        <ul class="sub">
            <li><a href="#">Pages</a></li>
            <li><a href="#">Archives</a></li>
            <li><a href="#">New Posts</a></li>
        </ul>
    <li><a href="./uitlening.html">Uitlening</a></li>

你需要保持<ul>里面的前一个<li>。所以这样做:

    <li><a href="./catalogus.html">Catalogus</a>
        <ul class="sub">
            <li><a href="#">Pages</a></li>
            <li><a href="#">Archives</a></li>
            <li><a href="#">New Posts</a></li>
        </ul></li>
    <li><a href="./uitlening.html">Uitlening</a></li>

现在,您可以通过定位标签来赋予样式<UL>,当您将鼠标悬停在标签上时,LI它就会显示出来。

li.drop ul {display: none; position: absolute;}
li.drop {position: relative}
li.drop:hover ul {display: block; left: auto; top: auto;}
于 2013-10-23T15:36:05.700 回答