为什么下拉列表在 IE 11 中移到左侧,但在 Chrome 或 FF 中却没有?

Why is dropdown moved to the left in IE 11 but not in Chrome or FF?

我创建了一个在 Chrome 和 Firefox 中运行良好的下拉菜单,但在 IE 11 中尝试时,下拉菜单内容最终显示在旁边。

我用谷歌搜索,但找不到解决方案。

请注意,它应该进入 Django 管理页面 header,这就是为什么有一些 !important。这也意味着下拉菜单应该位于页面上所有其他元素的顶部。

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<h1 style="text-align:left;float:left;"><a href="kalle.html">Test</a></h1>
<style type="text/css">
    .dropbtn {
    background-color: #417690;
    color: #f5dd5d !important;
    padding: 6px;
    font-size: 16px;
    border: none;
    cursor: pointer;

}

    .droplink {
    background-color: #417690;
    color: #f5dd5d !important;
    padding: 4px;
    font-size: 16px;
    border: none;
    cursor: pointer;

}

/* The container <div> - needed to position the dropdown content */
.dropdowncontainer {
    display: inline-block;
    padding-top: 10px;
}


.dropdown {
    float: left;
    display: inline-block;
}


/* 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: 1000;
}

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

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

/* 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: #376880;
}
.droplink:hover {
    background-color: #376880;
}
</style>

<div class="dropdowncontainer">
    <div class="dropdown">
        <a class="dropbtn" href="">XXX</a>
        <div class="dropdown-content">
            <a href="installations.html">Installations</a>
            <a href="files.html">Files</a>
            <a href="task.html">Tasks</a>
            <a href="release.html">Releases</a>
            <a href="copy.html">Copy</a>
        </div>
    </div>
        <a class="droplink" href="node.html">Nodes</a>
</div>
</body>
</html>

我用代码创建了一个 JSFiddle。任何帮助将不胜感激。

JSfiddle

尝试设置 .dropdown-content 左侧和顶部值。

尝试将 position: relative.dropdown class。

当未明确指定 position: relative 元素时,position: absolute 元素的行为因浏览器而异。因此,异常。

同时将 top: 0 & left: 0 添加到 .dropdown-content

.dropdown-content {
    top: 0;
    left: 0;
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1000;
}