我有两个下拉列表,它们按预期工作(它们显示悬停时的内容),但是,如果我点击列表外部(左侧)的区域,下拉列表仍会显示。奇怪的下拉行为css
我已经尝试修复CSS,但我一直无法指出问题。
有没有更好的样式下拉式的方法,因为我仍然是CSS的新手。
UPDATE:
测试这在Firefox和我无法重现该问题。我如何确保在所有浏览器中始终如一地运行?
.dropbtn {
color: white;
width: 200px;
margin-top: 160px;
margin-left: 276px;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
text-align: left;
font-weight: 900;
background: rgba(0, 173, 239, 1);
border-radius: 0px;
-moz-border-radius: 0px;
-webkit-border-radius: 50px 50px 50px 50px;
position: relative;
z-index: 2;
}
.dropdown {
position: relative;
display: inline-block;
width: 480px;
height: 0px;
background: antiquewhite;
}
.dropdown-content {
display: none;
position: relative;
z-index: 1;
background-color: #f9f9f9;
/* min-width: 160px; */
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
right: 5px;
top: -20px;
margin-left: 283px;
}
.sphere {
height: 45px;
width: 45px;
border-radius: 50%;
vertical-align: top;
/* position: relative; */
background: black;
display: inline-block;
position: relative;
margin-top: 165px;
margin-left: -55px;
z-index: 2;
}
.dropdown-content a {
table-layout: fixed;
color: black;
margin-left: -1px;
padding: 12px 16px 13px 30px;
text-decoration: none;
display: block;
border: 1px solid #000;
border-top: none;
font-size: 21px;
}
.dropdown-content a:first-child {
padding-top: 35px;
background: url("Images/sidearrow.png") no-repeat 7px 36px;
}
.dropdown a {
\t background:url("Images/sidearrow.png") no-repeat 7px;
}
.dropdown-content a:first-child:hover {
padding-top: 35px;
background: url("Images/sidewhite.png") no-repeat 3px 36px;
color:black;
background-color: rgb(255,131,0);
}
.dropdown-content a:hover {
\t background:url("Images/sidewhite.png") no-repeat 3px;
\t background-color: rgb(255,131,0);
\t color:white;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
div#arrow {
position: absolute;
margin-left: 10px;
margin-top: 11px;
}
/* SENTINAL */
.dropbtn-sentinal {
color: white;
width: 200px;
margin-top: 160px;
margin-left: 276px;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
text-align: left;
font-weight: 900;
background: rgba(0, 173, 239, 1);
border-radius: 0px;
-moz-border-radius: 0px;
-webkit-border-radius: 50px 50px 50px 50px;
position: relative;
z-index: 2;
}
.dropdown-sentinal{
position: relative;
display: inline-block;
width: 480px;
height: 0px;
background: antiquewhite;
}
.dropdown-content-sentinal {
display: none;
position: relative;
z-index: 1;
background-color: #f9f9f9;
/* min-width: 160px; */
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
right: 5px;
top: -20px;
margin-left: 283px;
}
.sphere-sentinal {
height: 45px;
width: 45px;
border-radius: 50%;
vertical-align: top;
/* position: relative; */
background: black;
display: inline-block;
position: relative;
margin-top: 165px;
margin-left: -55px;
z-index: 2;
}
.dropdown-content-sentinal a {
table-layout: fixed;
color: black;
margin-left: -1px;
padding: 12px 16px 13px 30px;
text-decoration: none;
display: block;
border: 1px solid #000;
border-top: none;
font-size: 21px;
}
.dropdown-content-sentinal a:first-child {
padding-top: 35px;
background: url("Images/sidearrow.png") no-repeat 7px 36px;
}
.dropdown-sentinal a {
\t background:url("Images/sidearrow.png") no-repeat 7px;
}
.dropdown-content-sentinal a:first-child:hover {
padding-top: 35px;
background: url("Images/sidewhite.png") no-repeat 3px 36px;
color:black;
background-color: rgb(255,131,0);
}
.dropdown-content-sentinal a:hover {
\t background:url("Images/sidewhite.png") no-repeat 3px;
\t background-color: rgb(255,131,0);
\t color:white;
}
.dropdown-sentinal:hover .dropdown-content-sentinal {
display: block;
}
.dropdown-sentinal:hover .dropbtn-sentinal {
background-color: #3e8e41;
}
div#arrow-sentinal {
position: absolute;
margin-left: 10px;
margin-top: 11px;
}
div#dropdown-one {
width: 500px;
height: 198px;
}
div#dropdown-two {
margin-left: 700px;
margin-top: -198px;
}
div#dropdown-content a {
text-decoration: none;
border: solid black 1px;
display: table-caption;
background-color: rgb(237,237,238);
background: url(Images/sidearrow.png) no-repeat 7px 36px;
}
<!DOCTYPE html>
<html>
<head>
\t <title>title</title>
\t <link rel="stylesheet" type="text/css" href="dropdown.css">
<meta charset="utf-8">
</head>
<body>
<div class="averios-header">
\t <div id="averios-logo">
\t \t <img src="averioslogo.png" width="176" height="129">
\t </div>
\t <div id="setting-dropdown">
\t \t <!-- SETTING DROPDOWN WILL GO HERE -->
\t </div>
\t <div id="header-hr">
\t </div>
</div>
<div id="log-in">
\t <div id="loginHeader">
\t \t <h1>Portal</h1>
\t </div>
\t <div id="welcome-text">
\t \t <p> Welcome name </p>
\t \t <p> Your last login was time on date </p>
\t \t <br>
\t \t <p> Please select an application below to begin </p>
\t </div>
</div>
<div id="dropdown-one">
\t <div class="dropdown">
\t <button class="dropbtn">SELECT</button>
\t <div class="sphere">
\t \t <div id="arrow">
\t \t \t <img src="C:\Users\mseh\Desktop\Images\arrow.png" width="29" height="27" alt=""/>
\t \t </div>
\t </div>
\t <div class="dropdown-content">
\t \t <a href="#">Link 1</a>
\t \t <a href="#">Link 1</a>
\t \t <a href="#">Link 1</a>
\t \t <a href="#">Link 1</a> \t \t
\t </div>
\t </div>
</div>
<div id="dropdown-two">
\t <div class="dropdown-sentinal">
\t <button class="dropbtn-sentinal">SELECT</button>
\t <div class="sphere-sentinal">
\t \t <div id="arrow-sentinal">
\t \t \t <img src="C:\Users\mseh\Desktop\Images\arrow.png" width="29" height="27" alt=""/>
\t \t </div>
\t </div>
\t <div class="dropdown-content-sentinal">
\t \t <a href="#">Link 1</a>
\t \t <a href="#">Link 1</a>
\t \t <a href="#">Link 1</a>
\t \t <a href="#">Link 1</a> \t
\t </div>
\t </div>
</div>
</body>
</html>
您已经测试了自己的例子,对不对?如果我超出清单的范围,清单就会关闭(应该如此)。所以或者这个例子不会给我们提供你遇到的问题,或者你正在经历这个问题,这让我质疑你正在使用的浏览器。因为上面的例子按预期工作。 – junkfoodjunkie
@junkfoodjunkie我刚刚在Firefox中测试,它没有问题。但CSS不会在Firefox中加载。任何建议与我如何解决这个问题有关? – Maddy
咦?我正在查看你的代码 - 它显示了一个蓝色的矩形,每边都有半个圆圈,当我将它悬停在它上面时,它变成绿色,并且下拉选择菜单。这看起来是一样的,并且在Safari,Firefox,Chrome和Opera中也是一样的。你使用的是什么浏览器? – junkfoodjunkie