正在处理一个项目,需要将我的导航栏缩放到汉堡菜单中以获取移动视图。我完成了大部分工作,但出于某种原因导航并未在汉堡包内折叠。在过去几个小时里一直在调整,但还没有找到解决方案。
我的小提琴:https://jsfiddle.net/jr01pvkL/8/
代码可能很乱,因为它是一个更大的项目的一部分而且我是初学者。
html
<header>
<nav class="floatfix nav">
<div id="hamburgerknop">
<span id="hamburger">☰</span>
</div>
<ul class="main-nav">
<li>
<a href="#" title="naar homepage">Home</a>
</li>
<li>
<a href="#" title="naar homepage">Over Ons</a>
</li>
<li>
<a href="#" title="naar homepage">Producten</a>
</li>
<li>
<a href="#" title="naar homepage">Workshop</a>
</li>
<li>
<a href="#" title="naar homepage">Klanten</a>
</li>
<li>
<a href="#" title="naar homepage">Contact</a>
</li>
</ul>
<ul class="icon-nav">
<li>
<a href="https://www.facebook.com/" class="icon icon-mono facebook"><span class="fa fa-facebook"></span></a>
</li>
<li>
<a href="https://twitter.com/?lang=nl" class="icon icon-mono twitter"><span class="fa fa-twitter"></span></a>
</li>
<li>
<a href="https://plus.google.com" class="icon icon-mono googleplus"><span class="fa fa-google-plus"></span></a>
</li>
<li>
<a href="#" class="icon icon-mono instagram"><span class="fa fa-instagram"></span></a>
</li>
</ul>
</nav>
</header>
css
html {
height: 100%;
color: #222;
font-size: 1em;
line-height: 1.4;
}
body {
font: 100%/1 "Coves", Arial, sans-serif;
color: rgb(246,246,226);
background-color: rgb(246,246,226);
height: 100%;
}
header {
/*background-color: rgba(255,255,255,0.5);*/
position: fixed;
left: 0;
height: 150px;
top: 0;
width: 100%;
z-index: 10;
display: block;
}
.logo {
z-index: 12;
position: absolute;
left: 50px;
top: 0;
display: block;
width: 150px;
padding-top: 10px;
}
.nav {
z-index: 11;
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
text-align: center;
transition: all 0.4s ease;
}
.non-transparent {
z-index: 11;
background-color: rgb(31,15,16) !important;
}
.main-nav {
list-style: none;
}
.nav li {
display: inline-block;
vertical-align: middle;
height: 120px;
letter-spacing: 1px;
text-transform: uppercase;
}
.nav li a {
position: relative;
top: 50%;
transform: translateY(-50%);
font-weight: bold;
text-decoration: none;
display: block;
line-height: 16px;
height: 16px;
padding: 25px 11px 24px;
}
.nav li a:hover {
color: rgb(212,192,152);
}
.icon-nav {
position: absolute;
right: 0px;
top: 0;
margin-right: 50px;
}
.icon {
display: inline-block;
zoom: 1;
vertical-align: top;
width: 44px;
height: 0;
padding-top: 44px;
overflow: hidden;
text-align: left;
white-space: nowrap;
}
@media screen and (max-width: 1200px) {
.icon-nav {
display: none;
}
}
@media (max-width: 500px) {
/* Hamburger-knop voor mobiele navigatie */
#hamburgerknop {
background: rgba(31,15,16, 0.35);
padding: 8px;
text-decoration: none;
position: fixed;
width: 100%;
z-index: 2;
}
#hamburgerknop span {
cursor: pointer;
display: block;
padding: 3px 4px 3px;
position: relative;
color: rgb(246,246,226);
font-size: 3em;
line-height: .8;
}
.nav ul {
list-style: none;
margin: 0;
width: 100%;
padding: 0;
border-bottom: 1px solid rgba(31,15,16);
}
.nav li {
display: block;
position: relative;
font-size: 1em;
font-weight: bold;
border-bottom: 1px solid #E44D26;
border-top: 1px solid #f17b54;
padding: 15px;
}
.nav li a {
display: inline !important;
background: none !important;
text-decoration: none;
}
.nav {
clear: both;
}
}
.expand {
display: block !important;
}
jquery(在html页脚中)
jQuery(function($) {
$('#hamburgerknop').click(function() {
$('.nav').toggleClass('expand');
});
});
TNX!
答案 0 :(得分:2)
您的功能正常,您只需要在媒体查询中添加一些css,如
.main-nav {
display: none;
}
.expand .main-nav {
display: block;
}