元素隐藏在其他元素后面
elements are hiding behind others
我正在尝试创建一个 html 页面,其中包含主页地图和菜单侧边栏。问题是我无法让 sidenav 打开按钮显示在地图前面或上方。它似乎总是在它后面,或者如果我弄乱了东西,我可以让地图消失,然后 sidenav 打开按钮可见并且工作正常。
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Test</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css' rel='stylesheet' />
<style>/*sidenav*/
html, body {
font-family: "Lato", sans-serif;
margin:0;
padding:0;
}
#map { position:absolute; top:0; bottom:0; width:100%; }
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 30px;
}
.sidenav a, .dropdown-btn {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
text-align: left;
cursor: pointer;
transition: 0.3s;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
}
#myInput {
font-size: 18px;
padding: 6px 8px 6px 16px;
border: none;
border-bottom: 1px solid #ddd;
}
.main {
margin-left: 10px;
font-size: 20px;
padding: 0px 10px;
}
.active {
background-color: #111;
color: white;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
}
.fa-caret-down {
float: right;
padding-right: 8px;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 30px;
margin-left: 50px;
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>
<div id='map'></div>
<script>//this is the map stuff//
mapboxgl.accessToken = 'pk.eyJ1IjoidHJveWIiLCJhIjoiY2pkb3F0cmJnMHA0YTJ4cXB3Mjc0Y3g0eCJ9.3Myq7AzC4yxR8hi9Ubchdw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-88.75, 42.15],
zoom: 8
});
</script>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">Home</a>
<button class="dropdown-btn">Select Congregation
<i class="fa fa-caret-down"></i>
</button>
<div id="myDropdown" class="dropdown-container">
<input type="text" placeholder="Search.." id="myInput" onkeyup="filterFunction()">
<a href="#Mt. Calm">Mt. Calm</a>
<a href="#Newark">Newark</a>
<a href="#Wildwood">Wildwood</a>
</div>
<a href="#">Contact</a>
<a href="#">About</a>
</div>
<div class="main">
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
<script>
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
function filterFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
div = document.getElementById("myDropdown");
a = div.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}
</script>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "260px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
在第 22 行中,将宽度值更改为 200px。您的 sidenav 看起来很好。已检查您的代码。
与其在导航菜单中设置 z-index,不如尝试将 z-index 设置为您的地图本身
z-index: -1;
顺便说一句,与其提供 google 驱动程序,不如直接在其中编写行代码:
https://meta.stackexchange.com/questions/51144/how-do-i-post-code-in-Whosebug
我正在尝试创建一个 html 页面,其中包含主页地图和菜单侧边栏。问题是我无法让 sidenav 打开按钮显示在地图前面或上方。它似乎总是在它后面,或者如果我弄乱了东西,我可以让地图消失,然后 sidenav 打开按钮可见并且工作正常。
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Test</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css' rel='stylesheet' />
<style>/*sidenav*/
html, body {
font-family: "Lato", sans-serif;
margin:0;
padding:0;
}
#map { position:absolute; top:0; bottom:0; width:100%; }
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 30px;
}
.sidenav a, .dropdown-btn {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
text-align: left;
cursor: pointer;
transition: 0.3s;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
}
#myInput {
font-size: 18px;
padding: 6px 8px 6px 16px;
border: none;
border-bottom: 1px solid #ddd;
}
.main {
margin-left: 10px;
font-size: 20px;
padding: 0px 10px;
}
.active {
background-color: #111;
color: white;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
}
.fa-caret-down {
float: right;
padding-right: 8px;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 30px;
margin-left: 50px;
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>
<div id='map'></div>
<script>//this is the map stuff//
mapboxgl.accessToken = 'pk.eyJ1IjoidHJveWIiLCJhIjoiY2pkb3F0cmJnMHA0YTJ4cXB3Mjc0Y3g0eCJ9.3Myq7AzC4yxR8hi9Ubchdw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-88.75, 42.15],
zoom: 8
});
</script>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">Home</a>
<button class="dropdown-btn">Select Congregation
<i class="fa fa-caret-down"></i>
</button>
<div id="myDropdown" class="dropdown-container">
<input type="text" placeholder="Search.." id="myInput" onkeyup="filterFunction()">
<a href="#Mt. Calm">Mt. Calm</a>
<a href="#Newark">Newark</a>
<a href="#Wildwood">Wildwood</a>
</div>
<a href="#">Contact</a>
<a href="#">About</a>
</div>
<div class="main">
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
<script>
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
function filterFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
div = document.getElementById("myDropdown");
a = div.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}
</script>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "260px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
在第 22 行中,将宽度值更改为 200px。您的 sidenav 看起来很好。已检查您的代码。
与其在导航菜单中设置 z-index,不如尝试将 z-index 设置为您的地图本身
z-index: -1;
顺便说一句,与其提供 google 驱动程序,不如直接在其中编写行代码: https://meta.stackexchange.com/questions/51144/how-do-i-post-code-in-Whosebug