html - 为什么这个 CSS 在我悬停时不创建新的菜单项?

标签 html css menu

我按照指南制作了下拉菜单,尽管我希望它们向右弹出,而不是向下弹出。但是,它不起作用。

我将把 CSS 和 HTML 都放在这里。

编辑:忘记了我可以轻松地在 Vim 中缩进所有代码,这使得复制所有文本并将其放入代码块变得容易得多。

JSFiddle Demo

CSS:

#menubox
{
    width: 8%;
    height: 30%;
    border: 10% solid #C7D93D;
    border-radius: 5%;
    position: fixed;
    margin-top: 12%;
    margin-left: 18%;
    font-family: Ubuntu, Lucida console, Futura;
    list-style: none;
    float: left;
}


#menubox ul li a
{
    text-align: left;
    font-size: 200%;
    color: #FFF0A5;
}

#menubox ul li
{
    color: #468966;
    font-family: Ubuntu, Lucida console, Futura;
    float: left;
    margin-right: 10px;
    position: relative;
}

#menubox ul
{
    color: #468966;
    font-family: Ubuntu, Lucida console, Futura;
}

#menubox ul ul
{
    position: absolute;
    left: -9999px;
    list-style: none;
}

#menubox ul ul li
{
    padding-top: 1px;
    float: none;
}

#menubox ul ul a
{
    white-space: nowrap;
}

#menubox ul li a:hover
{
    color: #FFB03B;
} 

#menubox ul li:hover ul
{
    left: 0;
}

#menubox ul li:hover a
{
    text-decoration: none;
}

#menubox ul li:hover ul li a:hover
{
    text-decoration: none;
}


div p
{
    color: #FFF0A5;
    text-align: center;
    position: relative;
    vertical-align: middle;
    display: inline-block;
    margin-top: 300px;
    line-height: 60px;
}

div ul ul
{
}


#circle
{
    border-radius: 100%;
    -webkit-border-radius: 100%;
    -moz-border-radius: 100%;
    background-color: #B64926;
    width: 500px;
    height: 500px;
    display: block;
    position: fixed;
    margin-top: 9%;
    margin-left: 52%;
    text-align: center;
}

#title
{
    text-color: #FFF0A5;
    font-size: 350%;
    display: inline;
    text-align: center;
}

body
{
    height: 100%;
    width: 100%;
    background-color: #468966;
    font-family: Ubuntu, Lucida console, Futura;
}

.link
{
    text-color: #FFF0A5;
    text-decoration: none;
    text-align: left;
}

HTML:

<!DOCTYPE HTML>
<html>
<head>
    <link href="stylesheet.css" rel="stylesheet" type="text/css">
    <title>Home</title>
</head>
<body>
    <div ID="menubox">
        <ul>
        <li><a href="http://folk.ntnu.no/arnstekl/" class="link">Home</a></li>
        <li><a href="#" class="link">Music</a></li>
            <ul>
                <li><a href="https://soundcloud.com/arnsteinkleven/" class="link">My music</a></li>
                <li><a href="http://folk.ntnu.no/arnstekl/gilberto.html" class="link">The Joao Gilberto project</a></li>
           </ul>

        <li><a href="https://www.github.com/arnstein" class="link">Github</a></li>

        <li><a href="http://www.flickr.com/photos/92472314@N03/" class="link">Pictures</a></li>

        </ul>

    </div>
    <div ID="circle">
        <p ID="title"> A <br> r <br> n <br> s <br> t <br> e <br> i <br> n </p>
    </div>
    </body>
</HTML>

最佳答案

您将在 ul 之前关闭 li 标记,但是由于 ul 的唯一有效子级是 li ,您需要在之后关闭它。

<li><a href="#" class="link">Music</a>
    <ul>
        <li><a href="https://soundcloud.com/arnsteinkleven/" class="link">My music</a></li>
        <li><a href="http://folk.ntnu.no/arnstekl/gilberto.html" class="link">The Joao Gilberto project</a></li>
    </ul>
</li>

关于html - 为什么这个 CSS 在我悬停时不创建新的菜单项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17366300/

相关文章:

javascript - 动态设置 iframe 高度

html - 使用 CSS 悬停时下拉菜单不起作用

html - 向现有 CSS 菜单添加更多级别

html - 移动设备的背景尺寸

javascript - 单击时获取父元素的 ID

css - 如何使用 CSS 将表格外的文本左对齐

css - 我的设备分辨率为 720px,但在浏览器中宽度为 360px

javascript - 如何自动换行 URL?

Android:Activity 和 Fragments 之间的 OptionMenu

html - 在单选组中对项目进行分组的可访问方式是什么? (HTML5/WAI-咏叹调)