html - 如何停止下拉列表出现在列表项的顶部

标签 html css web styling

因此,我正在尝试从列表项配置一个简单的下拉列表,但我终生无法弄清楚为什么当我将鼠标悬停在列表项上时它不会停止覆盖该列表项。这是 html:

<div class="dropdown" style="float:right">
                <li><a class="active dropbtn" href="">Profile</a></li>
                <div class="dropdown-content">
                <a href="#">Link 1</a>
                <a href="#">Link 2</a>
                <a href="logout.php?logout"><span class="glyphicon   glyphicon-log-out"></span>&nbsp; Logout</a></a>
                </div>
            </div>

设置样式的 css 是:

tr:hover {background-color: #f5f5f5}
th, td {
padding: 15px;
text-align: left;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 10;
}

/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}

/* Change the background color of the dropdown button when the dropdown     content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;

除此之外,尽管更改了下拉元素的 z-index,但我无法让菜单出现在父列表所在的菜单之外

感谢所有帮助

最佳答案

好吧,代码给了我一些错误....请看看这个 JSfiddle 并告诉我它现在是否工作?也请告诉我你想要什么,因为我有点困惑..

https://jsfiddle.net/xxsycmyj/

<div class="dropdown" style="float:left">
            <li><a class="active dropbtn" href="">Profile</a></li>
            <div class="dropdown-content">
            <a href="#">Link 1</a>
            <a href="#">Link 2</a>
            <a href="logout.php?logout"><span class="glyphicon   glyphicon-log-out"></span>&nbsp; Logout</a>
            </div>

我觉得 CSS 没问题。

关于html - 如何停止下拉列表出现在列表项的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39968213/

相关文章:

java - 发布时部署

mysql - 面向用户的 SQL 管理框架(针对非专家用户)

html - @Html.EditorFor 必需 = "required"不起作用

Html水平对齐问题

javascript - jQuery - 告诉页面何时滚动到并正在查看特定的 DIV

html - 如何使用边框分隔表格中的行

css - spring如何使用css文件

css - 响应式布局中的 Twitter bootstrap 最小宽度

php - 我将如何对 mySQL 数据库的每 4 行回显不同的内容

android - Android : what to do with low devicePixelRatio devices: tablets, 智能手机等网站?