[英]Mobile top navigation issue
我的网站是http://www.kaniamea.com/ph/ 。 请最小化屏幕或使用移动设备查看此页面。 然后,当您单击右上角菜单图标所在的位置时,标题菜单会随着显示下拉菜单而跳升(这将隐藏整个标题)。 有没有一种方法可以防止这种情况,所以当您单击菜单图标时,菜单将显示在下方,而不会在顶部隐藏标题? 谢谢大家,圣诞快乐!
<!-- Start Main -->
<div id="main">
<!-- Start Header -->
<div id="header">
<!-- Start Logo -->
<div id="logo">
<h1><a href="#">Logo</a></h1>
</div>
<!-- End Logo -->
<!-- Start Nav -->
<div id="nav" role="navigation"> <a href="#nav" title="Show navigation">Show navigation</a> <a href="#" title="Hide navigation" >Hide navigation</a>
<ul class="clearfix">
<li class="home"><a href="link.html">Home</a></li>
<li><a href="link.html">What Happened</a></li>
<li><a href="link.html">Today</a></li>
<li> <a href="javascript:void(0);" aria-haspopup="true"><span>Visit</span></a>
<ul>
<li> <a href="link.html">Tours</a></li>
<li> <a href="link.html">Directions</a></li>
<li><a href="link.html">Operating Hours</a></li>
<li><a href="link.html">Things To Do</a></li>
<li><a href="link.html">Before You Come</a></li>
</ul>
</li>
<li> <a href="javascript:void(0);" aria-haspopup="true"><span>Battleships</span></a>
<ul>
<li> <a href="link.html">Arizona</a></li>
<li><a href="link.html">Oklahoma</a></li>
<li><a href="link.html">West Virginia</a></li>
<li><a href="link.html">California</a></li>
<li><a href="link.html">Nevada</a></li>
<li><a href="link.html">Pennsylvania</a></li>
<li><a href="link.html">Maryland</a></li>
<li><a href="link.html">Missouri</a></li>
<li><a href="link.html">Tennessee</a></li>
<li><a href="link.html">Utah</a></li>
</ul>
</li>
</ul>
</div>
<!-- End Nav -->
</div>
<!-- End Header -->
Nav css是:
#nav {
display: block;
background-image: url("images/nav-bg.png");
background-repeat: no-repeat;
width: 681px;
height: 63px;
float: right;
margin-right: -1.77em;
margin-top: 1.6em;
}
#nav > a {
display: none;
}
#nav li {
position: relative;
}
#nav li a {
padding: 20px 25px 20px 25px;
color: #FFF;
font-size: 1.1em !important;
text-decoration: none;
font-weight: bold;
display:block;
}
#nav li a:hover {
background-image:url(images/hover.png);
background-repeat: repeat-x;
}
#nav span:after {
width: 0;
height: 0;
border: 0.313em solid transparent; /* 5 */
border-bottom: none;
border-top-color: #F81302;
content: '';
vertical-align: middle;
display: inline-block;
position: relative;
right: -0.313em; /* 5 */
}
/* first level */
#nav > ul > li {
float: left;
z-index:1000;
overflow:visible;
}
#nav > ul > li > a {
height: 100%;
font-size: 1.1em; /* 24 */
}
#nav > ul > li:hover > a, #nav > ul:not( :hover ) > li.active > a {
background-image:url(images/hover.png);
background-repeat: repeat-x;
}
/* second level */
#nav li ul {
background-color: #BE0115;
display: none;
position: absolute;
top: 100%;
width:170px;
}
#nav li:hover ul {
display: block;
left: 0;
right: 0;
}
#nav li:not( :first-child ):hover ul {
left: -1px;
}
#nav li ul a {
font-size: 1.25em; /* 20 */
border-top: 1px solid #D90018;
padding: 0.75em; /* 15 (20) */
}
#nav li ul li a:hover, #nav li ul:not( :hover ) li.active a {
background-image:url(images/drop-nav-bg.png);
background-repeat: repeat-x;
}
@media only screen and ( max-width: 800px ) {
html {
font-size: 75%; /* 12 */
}
#nav {
width: 100%;
position: static;
margin: 0;
top: auto;
left: auto;
background-image: none;
float: right;
height:auto;
}
#nav > a {
width: 40px;
height: 40px;
text-align: left;
text-indent: -9999px;
background: url("images/menu-icon.png") repeat scroll center center #4C8FEC;
float: right;
margin-top: -45px !important;
}
#nav > a:before, #nav > a:after {
margin-right:40px;
margin-top:10px;
content: '';
}
#nav > a:after {
margin-top:10px;
}
#nav:not( :target ) > a:first-of-type, #nav:target > a:last-of-type {
display:block;
}
#nav > ul > li:hover > a, #nav > ul:not( :hover ) > li.active > a {
background-image:none;
}
/* first level */
#nav > ul {
height: auto;
display: none;
left: 0;
right: 0;
height: 3.75em;
width: 200px;
float:right;
}
#nav:target > ul {
display: block;
}
#nav > ul > li {
width: 100%;
float: right;
}
#nav > ul > li > a {
height: auto;
text-align: left;
padding: 0 0.833em; /* 20 (24) */
height: 100%;
font-size: 1.1em; /* 24 */
line-height: 2.5em; /* 60 (24) */
background-color: #BE0115;
}
#nav > ul > li > a:hover {
background-image:url(images/drop-nav-bg.png);
background-repeat: repeat-x;
}
#nav > ul > li:not( :last-child ) > a {
border-right: none;
}
#nav > ul > li:not(:last-child) > a {
border-right: medium none;
border-bottom: 1px solid #D90018;
}
/* second level */
#nav li ul {
padding-top: 0;
width: 200px;
position: static;
}
}
您看到的问题源于使用#nav:target
渲染导航。 您正在告诉浏览器“仅在网址栏为http://www.kaniamea.com/ph/#nav
时显示菜单...通过应用#nav
,还可以告诉浏览器使用以下命令跳转到元素id="nav"
。
而不是让CSS依赖:target
,您可以执行#nav.showNav
,并添加一个可切换showNav类的click事件。
$(function() {
$('.toggle-nav').click(function(event){
event.preventDefault();
$('#nav').toggleClass('showNav');
});
});
重要的是要调用event.preventDefault();
,这可以防止您在单击链接时发生默认的点击行为。
这是您的网站,此处带有示例jquery: http : //jsfiddle.net/zc6w276o/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.