有没有办法停止在不透明叠加层上显示图像?

Is there a way to stop the images show on top of the opacity overlay?

我是 HTML/CSS 的新手。我创建了这个侧边栏,当点击它时,它会从左侧滑动,当它滑动时,会显示一个不透明的背景。不幸的是,图像显示在不透明叠加层之上,我找不到让它停止如此明亮地显示在不透明之上的问题。我正在为我们的学科老师要求的项目做这件事。

我已经尝试过使用 z-index 但我并不是真正的专家,因为我是初学者并且我从 w3schools.com

等网站获得帮助
 <style>
    body {
    margin: 0;
    font-size: 32px;
    font-family: Arial, Helvetica, sans-serif;
 }

.header {
  background-color: #fffff;
  padding: 30px;
  text-align: center;
}

#navbar {
  overflow: hidden;
  padding: 16px 14px;
  background-color: #72cef6;
  z-index: 90;
}

}

#navbar a:hover {
  background-color: #ccebff;
  color: #666666 
}

.content {
  padding: 16px;
}

.sticky {
  position: fixed;
  top: 0;
  width: 100%;
}

.sticky + .content {
  padding-top: 60px;
}
</style>
</head>
<body>

<div id="navbar">
<style>
body {
    font-family: "Calibri", sans-serif;
}

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #ffffff;
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
}

.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 18px;
    color: #ff9966;
    display: block;
    transition: 0.4s;
}
.sidenav a:hover {
    color: #99d6ff;
}

.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 22px;
    margin-left: 50px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidenav a {font-size: 18px;}
}
</style>
</head>
<body>

<div id="mySidenav" class="sidenav">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <a href="Moderator's Profile.html">Modertor's Page</a> 
  <a href="#">Members and Officers</a> 
  <a href="Constitution and By Laws.html">Constitution and By Laws</a> 
  <a href="#">Activity Layout</a>
  <a href="about.html">Info.</a> 
</div>

<span style="font-size:18px;cursor:pointer" onclick="openNav()"><font 

color="#72cef6">___</font><img src="menu.png" height="24"></span>


<style>
element.style {
    display: block;
}

.mm-open .mm-fullscreen-bg {
    cursor: pointer;
    background-color: rgba(0,0,0,0.55);
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
    width: 100%;
    height: 100%;
    z-index: 999;
    display: none;
}
</style>

<div class="mm-fullscreen-bg" style="display: block;"></div>

<script>
function openNav() {
    document.getElementById("mySidenav").style.width 
="250px";document.body.style.backgroundColor = 
"rgba(0,0,0,0.4)";object.style.zIndex="999";
}

function closeNav() {
    document.getElementById("mySidenav").style.width = 
"0";document.body.style.backgroundColor 

= "white";
}
</script>
</div>

<script>
window.onscroll = function() {myFunction()};

var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;

function myFunction() {
  if (window.pageYOffset >= sticky) {
    navbar.classList.add("sticky")
  } else {
    navbar.classList.remove("sticky");
  }
}
</script>

我只想达到this.的结果。

哦,不要介意 sidenav 上提供的链接。

也许这会起作用,将收益的一部分带入DIV并降低不透明度

我假设你在 w3schools

上使用这个例子

所以你可以实现这个给你的 img 标签一个 id 假设 some-image

<img id='some-image' src="https://via.placeholder.com/150">

比将此添加到 openNav();

document.getElementById('some-image').style.opacity = "0.2";

关闭时,您可以在 closeNav()

上恢复为白色
document.getElementById('some-image').style.opacity = "1";

我为您创建了 jsfiddle 示例,请查看

https://jsfiddle.net/whatatimetobealive/4wack0y1/11/

如果您提供所有代码,我也可以帮助您,但目前缺少 body 部分,因此很难假设您那里到底有什么。

希望对您有所帮助...