Javascript 如何将导航栏显示设置从flex更改为block以实现响应性显示?
当浏览器窗口缩小时,我试图编写一个响应迅速的导航条汉堡。目前,导航栏显示为“flex”,但当我缩小浏览器窗口以弹出汉堡时,链接不会以列表格式显示(除非我将导航栏的显示更改为“block”,我不希望将其作为默认代码)。基本上,我想知道当浏览器窗口激活汉堡包时,如何编码导航栏从“flex”更改为“block”。以下是该网站的链接: 我正在通过Wordpress的后端工作Javascript 如何将导航栏显示设置从flex更改为block以实现响应性显示?,javascript,html,css,Javascript,Html,Css,当浏览器窗口缩小时,我试图编写一个响应迅速的导航条汉堡。目前,导航栏显示为“flex”,但当我缩小浏览器窗口以弹出汉堡时,链接不会以列表格式显示(除非我将导航栏的显示更改为“block”,我不希望将其作为默认代码)。基本上,我想知道当浏览器窗口激活汉堡包时,如何编码导航栏从“flex”更改为“block”。以下是该网站的链接: 我正在通过Wordpress的后端工作 .navbar { z-index: 1; font-family: 'Lyon'; background-color
.navbar {
z-index: 1;
font-family: 'Lyon';
background-color: white;
position: fixed;
bottom: 0;
width: 100%;
border-top: .05rem solid;
display: flex;
justify-content: space-between;
padding: 14px 16px;
}
.navbar a {
color: black;
font-family: 'Lyon';
font-size: 24px;
text-align: center;
text-decoration: none;
position: relative;
}
.navbar a:hover {
color: black;
font-family: 'Lyon';
text-decoration: none;
}
.navbar a:before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: #000;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.navbar a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.navbar a.active {
background-color: white;
color: black;
font-style: none;
font-family: 'Lyon';
}
.navbar .icon {
display: none;
}
@media screen and (max-width: 600px) {
.navbar a {
display: none;
}
.navbar a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.navbar.responsive .icon {
position: absolute;
right: 0;
bottom:0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
}
函数myFunction(){
var x=document.getElementById(“myNavbar”);
如果(x.className==“导航栏”){
x、 类名+=“响应”;
}否则{
x、 className=“navbar”;
}
}
为什么有两个相同的600px查询?您需要以设置display flex的父元素为目标。在你的情况下,这是你的导航栏,而不是锚标签
.navbar.responsive {
display: block;
}
为什么您有两个相同的600px查询?您需要以设置display flex的父元素为目标。在你的情况下,这是你的导航栏,而不是锚标签
.navbar.responsive {
display: block;
}
你的汉堡菜单在哪里??你的汉堡菜单在哪里??谢谢,文斯。成功了。对于600px的两个相同的查询,这是我第一次编码,所以它可能是糟糕的编码!谢谢,文斯。成功了。对于600px的两个相同的查询,这是我第一次编码,所以它可能是糟糕的编码!