我有一个 JS 函数,用于响应式导航,带有汉堡按钮,可以在屏幕太小时隐藏和显示导航。
我的问题是,即使 CSS 样式显示:none,导航的链接也会在加载时显示,之后按钮将按预期工作并让我在display: none和 之间切换display: flex。是什么导致它display: none在加载时忽略?
function myBurger() {
var x = document.getElementById("navLinks");
if (x.style.display === "none") {
x.style.display = "flex";
} else {
x.style.display = "none";
}
}Run Code Online (Sandbox Code Playgroud)
.navigation1 {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
padding: 3rem 3rem;
.logo img {
height: 5rem;
}
i {
display: none;
}
.navLinks {
display: flex;
a {
padding-left: 2rem;
align-self: center; //vertical align
color: $secondaryColor;
} …Run Code Online (Sandbox Code Playgroud)