【发布时间】:2020-05-02 15:29:21
【问题描述】:
我想在页面加载时显示整页叠加,并能够通过单击 X 关闭叠加来关闭叠加。因此,在页面加载时默认显示叠加层,然后如果它被关闭,则显示网站的其余部分(此处未包含代码)。
我尝试了以下方法,但不知道为什么它不起作用:
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus { color: #f1f1f1; }
@media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
<div id="myNav" class="overlay">
<div class="overlay-content">
<a href="#">Something</a>
</div>
</div>
【问题讨论】:
-
尝试删除
.overlaycss 中的width: 0- 我会添加right: 0:) -
是的,这就像做梦一样。谢谢,@Teknotica
-
很高兴听到!欢迎你:)
标签: javascript html css