我正在尝试在断点或媒体查询中使此菜单崩溃。菜单目前只有折叠菜单选项。我正在尝试添加非折叠选项,以便用户可以全屏查看链接的名称。菜单应仅在较小的设备上折叠。我尝试使用bootstrap实现此功能,但没有运气。基本上我只想简单地使用文本链接,然后当屏幕大小减小导航栏折叠并显示“汉堡菜单”时。
CodePen没有破坏引导程序实现。
http://codepen.io/anon/pen/dPaVdO
HTML
<body>
<header id="mast" class="">
<!-- Logo -->
<h1 id="logo">
pic
</h1>
<!-- Main Nav-->
<a id="toggle" href="#"><div class="menubars"></div></a>
<nav>
<div class="nav-background">
<ul>
<li>
<a href="">Hello</a>
</li>
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Bye</a></li>
</ul>
</div>
</nav>
</header>
CSS
body {
font-family: "Helvetica Neue", Helvetica,arial, sans-serif;
font-size: 100%;
margin: 0;
padding: 0;
}
@media (min-width: 45em) {
body {
font-size: 120%;
}
}
@media (min-width: 65em) {
body {
font-size: 130%;
}
}
@media (min-width: 85em) {
body {
font-size: 150%;
}
}
a {
text-decoration: none;
}
header {
position: fixed;
width: 100%;
background: rgba(0, 0, 0, 0.8);
display: block;
top: 0;
padding: 0;
z-index: 8;
height: 3.5em;
}
header h1#logo {
color: #fff;
font-size: 1em;
margin: 0 !important;
padding: .4em 1em 0;
position: absolute;
display: inline-block;
vertical-align: middle;
float: left;
padding: 1em 0.5em 0;
top: 0;
}
header nav p {
font-size: 80%;
color: #12384E;
margin: 0 0 -1em;
padding: 0;
font-weight: 400;
}
header nav ul {
margin: 0;
padding: 0;
line-height: inherit;
font-size: inherit;
visibility: hidden;
top: -5%;
width: 100%;
padding: 0;
opacity: 0;
display: table-cell;
vertical-align: middle;
-webkit-transform: perspective(600px) rotateX(10deg);
transform: perspective(600px) rotateX(10deg);
-webkit-transition: all 0.5s cubic-bezier(0.7, 0, 0.36, 0.63);
-moz-transition: all 0.5s cubic-bezier(0.7, 0, 0.36, 0.63);
-o-transition: all 0.5s cubic-bezier(0.7, 0, 0.36, 0.63);
transition: all 0.5s cubic-bezier(0.7, 0, 0.36, 0.63);
}
header nav ul li {
list-style: none;
text-align: center;
}
header nav ul li a {
display: block;
color: #fff;
padding: .5em 0;
width: 100%;
display: block;
font-size: 200%;
font-weight: 600;
}
header nav ul li a:hover {
background: rgba(255, 255, 255, 0.8);
}
header nav ul li a:focus {
outline: 0;
}
header nav ul li a:hover, header nav ul li a:active {
color: #0e1718 !important;
}
header .nav-background {
z-index: 99;
position: fixed;
top: 0;
width: 100%;
height: 100%;
background: none;
display: table;
-webkit-transition: background-color 0.6s cubic-bezier(0.7, 0.01, 0.3, 1);
-moz-transition: background-color 0.6s cubic-bezier(0.7, 0.01, 0.3, 1);
-o-transition: background-color 0.6s cubic-bezier(0.7, 0.01, 0.3, 1);
transition: background-color 0.6s cubic-bezier(0.7, 0.01, 0.3, 1);
}
header #toggle {
height: 3em;
z-index: 999;
padding: 1.5em 1em 0;
cursor: pointer;
position: fixed;
top: 0;
right: .5em;
-webkit-transition: padding-top 0.6s cubic-bezier(0.1, 0.01, 0.3, 1);
transition: padding-top 0.6s cubic-bezier(0.1, 0.01, 0.3, 1);
}
header #toggle:hover {
transition: top, 0.5s, ease-in-out;
}
header #toggle:hover .menubars:before {
top: -9px;
}
header #toggle:hover .menubars:after {
top: 9px;
}
.menubars {
width: 24px;
height: 4px;
margin: 10px 0;
background: #fff;
position: relative;
z-index: 999 !important;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.menubars:before {
top: -8px;
}
.menubars:after {
top: 8px;
}
.menubars:after, .menubars:before {
content: '';
display: block;
width: 24px;
height: 4px;
background: #EC008C;
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.menubars {
width: 24px;
height: 4px;
margin: .2em 0;
background: #FFF;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.menubars:before {
top: -8px;
}
.menubars:after {
top: 8px;
}
.menubars:after, .menubars:before {
content: '';
display: block;
width: 24px;
height: 4px;
background: #FFF;
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.js-open {
height: 100%;
}
.js-open header {
margin-top: 0px;
background: none;
}
.js-open .menubars {
background: none !important;
}
.js-open .menubars:after {
top: 0 !important;
background: #fff !important;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
.js-open .menubars:before {
top: 0 !important;
background: #fff !important;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.js-open .nav-background {
background: rgba(27, 128, 167, 0.9) !important;
}
.js-open ul {
top: 0;
visibility: visible;
opacity: 1;
margin-top: 0;
-webkit-transform: perspective(600px) rotateX(0deg);
-moz-transform: perspective(600px) rotateX(0deg);
-ms-transform: perspective(600px) rotateX(0deg);
-o-transform: perspective(600px) rotateX(0deg);
transform: perspective(600px) rotateX(0deg);
}
JS(JQuery)
$("a#toggle").on('click', function(e) {
$('body').toggleClass('js-open');
$('nav').toggleClass('js-open');
e.preventDefault();
});
$(".nav-background").on('click', function() {
$('body, nav').removeClass('js-open');
});
答案 0 :(得分:2)
您需要更改所需断点的显示样式/不透明度。例如:
@media all and (min-height: 1000px) {
header nav ul {
visibility: visible;
opacity: 1;
}
.menubars {
display: none;
}
}