由于某种原因,此元素(菜单元素)在网站 (XXXXXXXXXXXXXXXXX.com) 上不可单击,但仅在主页上不可单击。
该元素在其他页面和编辑器中运行得非常好。
我无法确定是什么导致它在主页上损坏。
我正在使用 Chrome 的调试器进行检查,但仍然没有找到问题,更不用说如何解决它了。
问:导致此问题的可能原因是什么?您认为解决问题的良好起点是什么?
网站:
www.somewhatmystical.com
菜单元素: https://www.w3schools.com/code/tryit.asp?filename=GD13CSPL7EEC
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: 'Lato', sans-serif;
}
* {
box-sizing: border-box;
}
.column1 {
color: white;
float: left;
width: 50%;
padding-left: 200px;
padding-right: 100px;
padding-top: 200px;
text-align: right;
font-size: 50px;
height: 575px;
border-right: 1px solid gray;
background-color: black;
}
.column2 {
color: white;
float: right;
width: 50%;
text-align: left;
padding: 10px;
font-size: 22px;
padding-left: 100px;
padding-top: 150px;
text-decoration: none;
height: 575px;
background-color: black;
}
a:link {
color: white;
}
a:hover {
color: #C0A539;
}
.row:after {
content: "";
display: table;
clear: both;
}
.overlay {
height: 0px;
width: 100%;
position: fixed;
top: 0;
z-index: 1;
top: 0;
left: 0;
bottom: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
color: #FFFFFF;
}
.overlay a {
padding: 8px;
text-decoration: none;
color: #FFFFFF;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #C0A539;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
@media screen and (max-height: 450px) {
.overlay a {
font-size: 20px
}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
</style>
</head>
<body>
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div class="overlay-content">
<div class="row">
<div class="column1">
<p>welcome to our online art journey. You can read our thoughts or you can simply write to us</p><br><br>
</div>
<div class="column2">
<a href="#" style="text-decoration: none;">blog</a>
<a href="#" style="text-decoration: none;">quotes</a>
<a href="#" style="text-decoration: none;">shop</a>
<a href="#" style="text-decoration: none;">about</a>
<a href="#" style="text-decoration: none;">contact</a>
<br><br><br><br><br>
</div>
</div>
</div>
</div>
<span style="font-size:50px;cursor:pointer;color:rgba(192,192,192,0);text-align:center;display:block;margin-top: -65px" onclick="openNav()">MENU</span>
<script>
function openNav() {
document.getElementById("myNav").style.height = "100%";
}
function closeNav() {
document.getElementById("myNav").style.height = "0";
}
</script>
</body>
</html>
最佳答案
这是可以接受的。它在功能上的问题确实是关于显示。您可以更改显示高度,但您还应该尝试更改菜单中子元素的样式
<script>
function openNav() {
document.getElementById("myNav").style.display= "contents";
}
function closeNav() {
document.getElementById("myNav").style.height = "none";
}
</script>
关于javascript - JS/CSS - 函数 openNav() 不适用于主页(仅),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60766812/