首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS固定下拉菜单行为怪异

CSS固定下拉菜单行为怪异
EN

Stack Overflow用户
提问于 2017-10-10 04:28:35
回答 1查看 96关注 0票数 0

有人知道为什么我的下拉菜单是这样的吗?(按菜单右边的汉堡包)。显然,定位是问题所在,但是,我需要在同一时间把它固定在顶部,这样我就没有选择了.如果我正确理解了定位..。

代码语言:javascript
复制
$('.hamburger').click(function(e){
		
		e.preventDefault();
	
		if ($("#menu").is(":visible")) {
		
			/* MENU FADES IN */
			$(".hamburger").removeClass('is-active');
			$("#menu").slideUp(400);
			
			$(".page-1-heading, .play-logo").fadeIn(500);
			$('.respm1, .respm2, .respm3, .respm4, .respm5, .respm6').toggleClass("animate");
			
		} else {
		
			/* MENU FADES OUT */
			$(".hamburger").addClass('is-active');
			$('.respm1, .respm2, .respm3, .respm4, .respm5, .respm6').toggleClass("animate");
			$("#menu").slideDown(400);
			
			$(".page-1-heading, .play-logo").fadeOut();
			
		}
	
	});
代码语言:javascript
复制
#responsive-menu {
		position: fixed;
		background-color: #000000;
		width: 100%;
		top: 0;
		left: 0;
		z-index: 999;
	}
.logo-2 {
		position: relative;
		float: left;
		top: 12px;
		left: 4%;
		z-index: 999;
		font-family: 'Helvetica-Neue', sans-serif;
		color:rgba(255,255,255,1);
		width: auto;
		height: 35px;
		
		transition: all 1s ease-out;
		-webkit-transition: all 1s ease-out;
	}
.hamburger {
	  position: relative;
	  float: right;
	  right: 5%;
	  z-index: 999;
	  opacity: 1;
	  cursor: pointer;
	  transition-property: opacity, filter;
	  transition-duration: 0.15s;
	  transition-timing-function: linear;
	  font: inherit;
	  color: inherit;
	  text-transform: none;
	  background-color: transparent;
	  border: 0;
	  overflow: visible; 
	  margin-bottom: 20px;
}
#menu {
		display: none;
		width: 100%;
		background-color: #f9f9f9;
		box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
#menu a {
		float: none;
		color: black;
		padding: 12px 16px;
		text-decoration: none;
		display: block;
		text-align: left;
		z-index: 4;
		color: #333436;
		text-decoration: none;
		cursor: pointer;
		font-size: calc(13px + 0.3vw);
		text-transform: uppercase;
		letter-spacing: 3px;
		border-radius: 0.2em;
		-webkit-transition: 350ms ease all;
		-moz-transition: 350ms ease all;
		transition: 350ms ease all;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="responsive-menu">
		<div id="wrapper">
			<div class="hamburger">
				<img src="http://goodstuffcommunications.com/wp-content/uploads/2015/08/xheadway-imported-image1.png.pagespeed.ic.rjlAN89gbj.png" class="logo-2" alt="Mountain View">
			</div>
			<img src="https://upload.wikimedia.org/wikipedia/commons/6/6f/HP_logo_630x630.png" class="logo-2" alt="Mountain View">
		</div>
			
		<!-- Menu content below -->
		<div id="menu">
			<a href="#">Services</a>
			<a href="#">Clients</a>
			<a href="#">About</a>
			<a href="#">Video</a>
			<a href="#">Contact</a>
		</div>
</div>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-10 04:33:28

您已经使用浮动左和右的标志和菜单,所以只有这样才会发生。如果您将clear:both交给#menu,它将修复

代码语言:javascript
复制
$('.hamburger').click(function(e){
		
		e.preventDefault();
	
		if ($("#menu").is(":visible")) {
		
			/* MENU FADES IN */
			$(".hamburger").removeClass('is-active');
			$("#menu").slideUp(400);
			
			$(".page-1-heading, .play-logo").fadeIn(500);
			$('.respm1, .respm2, .respm3, .respm4, .respm5, .respm6').toggleClass("animate");
			
		} else {
		
			/* MENU FADES OUT */
			$(".hamburger").addClass('is-active');
			$('.respm1, .respm2, .respm3, .respm4, .respm5, .respm6').toggleClass("animate");
			$("#menu").slideDown(400);
			
			$(".page-1-heading, .play-logo").fadeOut();
			
		}
	
	});
代码语言:javascript
复制
#responsive-menu {
		position: fixed;
		background-color: #000000;
		width: 100%;
		top: 0;
		left: 0;
		z-index: 999;
	}
.logo-2 {
		position: relative;
		float: left;
		top: 12px;
		left: 4%;
		z-index: 999;
		font-family: 'Helvetica-Neue', sans-serif;
		color:rgba(255,255,255,1);
		width: auto;
		height: 35px;
		
		transition: all 1s ease-out;
		-webkit-transition: all 1s ease-out;
	}
.hamburger {
	  position: relative;
	  float: right;
	  right: 5%;
	  z-index: 999;
	  opacity: 1;
	  cursor: pointer;
	  transition-property: opacity, filter;
	  transition-duration: 0.15s;
	  transition-timing-function: linear;
	  font: inherit;
	  color: inherit;
	  text-transform: none;
	  background-color: transparent;
	  border: 0;
	  overflow: visible; 
	  margin-bottom: 20px;
}
#menu {
        clear: both;
		display: none;
		width: 100%;
		background-color: #f9f9f9;
		box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
#menu a {
		float: none;
		color: black;
		padding: 12px 16px;
		text-decoration: none;
		display: block;
		text-align: left;
		z-index: 4;
		color: #333436;
		text-decoration: none;
		cursor: pointer;
		font-size: calc(13px + 0.3vw);
		text-transform: uppercase;
		letter-spacing: 3px;
		border-radius: 0.2em;
		-webkit-transition: 350ms ease all;
		-moz-transition: 350ms ease all;
		transition: 350ms ease all;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="responsive-menu">
		<div id="wrapper">
			<div class="hamburger">
				<img src="http://goodstuffcommunications.com/wp-content/uploads/2015/08/xheadway-imported-image1.png.pagespeed.ic.rjlAN89gbj.png" class="logo-2" alt="Mountain View">
			</div>
			<img src="https://upload.wikimedia.org/wikipedia/commons/6/6f/HP_logo_630x630.png" class="logo-2" alt="Mountain View">
		</div>
			
		<!-- Menu content below -->
		<div id="menu">
			<a href="#">Services</a>
			<a href="#">Clients</a>
			<a href="#">About</a>
			<a href="#">Video</a>
			<a href="#">Contact</a>
		</div>
</div>

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46658637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档