html - CSS下拉菜单问题和定位

标签 html css drop-down-menu

我在使用 CSS 下拉菜单时遇到了一些问题。

这是该站点的链接:rpg.vacau.com

有两个问题:

  1. 当您将鼠标悬停在齿轮上时,它不仅会下拉一个小菜单,还会下拉一个占据右侧剩余空间的黑色条。

  2. 齿轮就在标题的旁边,我希望它在右侧而不是绝对定位,因为菜单是相对定位的。

差不多了,我该如何修复随菜单一起下拉的奇怪黑条,以及如何将齿轮和菜单移动到右侧?在此先感谢,并希望这是有道理的。

index.html

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Lite RPG</title>
    <link rel="stylesheet" type="text/css" href="/css/web.css" />
    <link rel="stylesheet" type="text/css" href="/css/fonts.css" />
</head>
<body>
<nav>
    <ul>
        <li><a id="title" href="#">iON»</a></li>
        <li><a id="settings" href="#"><img src="/images/settings.png" height="20"
width="20" /></a>
        <ul>
           <li><a href="#">Stuff</a></li>
           <li><a href="#">Stuff</a></li>
        </ul>
     </li>
  </ul>
</nav>
</body>
</html>

网络.css

body, ul { 
    margin: 0;
    padding: 0;
}

nav ul {
    background-color: #1b1b1b;
    display: table;
    position: relative;
    list-style: none;
    top: 0;
    height: 50px;
    width: 100%;
}

nav ul li {
    float: left;
}

nav ul li a {
    display: table-cell;
    height: 50px;
    line-height: 50px;
    padding: 0 65px;
    font-family: "Champagne & Limousines";
    font-size: 16px;
    color: #ffffff;
    text-decoration: none;
    background-color: #1b1b1b;
}

nav ul li a:hover {
    background-color: #292929;
}

nav #title {
    font-family: Lobster;
    font-size: 36px;
    line-height: 50px;
    border-right: 1px solid #ffffff;
}

nav #settings {
    top: 0px;
    left: 1000px;
}
nav ul ul {
    display: none;
    position: absolute;
    top: 100%;
}

nav ul ul li {
    float: none;
    position: relative;
}

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

最佳答案

在您的 CSS 文件中替换以下 2 个条件

nav ul ul {
    display: none;
    position: absolute;
    top: 100%;
    right: 0px;
    width: auto;
}

nav ul ul li {
    float: left;
    position: relative;
    clear: both; 
}


li你想发送到右边,添加一个float: right; CSS 规则。例如:

<li style="float: right;">


编辑

要在鼠标位于子菜单内时保持图标突出显示,

nav li:hover #menu {
    background-color: #292929;
}

关于html - CSS下拉菜单问题和定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17091610/

相关文章:

javascript - 想从服务器端清除 UIWebView 缓存

javascript - 按下 Enter 时将连字符添加到文本区域

html - 将 html 表单与 css 问题对齐

javascript - 如何显示12小时制并显示实际时间和存储时间之间的时差

php - 如果屏幕尺寸小于 Y,则在 php 文件的 body 标签内显示 X

html - 忽略HTML 5视频和随机视频加载

javascript - Dropzone 固定高度并水平滚动

html - 在 css-grid 框之一内对齐输入框

javascript - 使用 jquery 时下拉 selectedindex 不触发

php - 查看数组中的一项是否为真