我是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()">×</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上提供的链接。
答案 0 :(得分:1)
也许这会奏效,将部分收益纳入DIV并减少不透明性
答案 1 :(得分:1)
我假设您在w3schools
上使用了此示例因此,您可以为 img 标签添加 id ,例如 某些图片
<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 部分已丢失,因此很难假设您在那里到底有什么。
希望有帮助...