响应式菜单问题

时间:2016-12-08 08:20:24

标签: html css responsive

我目前正致力于http://jonathan.ohrstrom.nu,我正试图通过响应式设计获得正常运行的链接。如果窗口宽度小于1000px,则链接消失并显示菜单按钮;创建一个下拉菜单。



 /* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
    function myFunction() {
        var x = document.getElementById("topnav");
        if (x.className === "menuList") {
            x.className += " responsive";
        } else {
            x.className = "menuList";
        }
    }

    .menu_wrapper {
    	width: 100%;
    	height: 70px;
    	background-color: rgba(45, 45, 45, .9);
    	left: 0;
    	top: 0;
    	position: fixed;
    	z-index: 99;
    	box-shadow: 0 3px 0 rgba(229, 160, 0, .9);
    }
    .menu_content {
    	width: 1000px;
    	margin-left: auto;
    	margin-right: auto;
    	line-height: 70px;
    	color: #a0a0a0;
    	font-weight: 400;
    	font-family: 'Roboto', sans-serif;
    	text-transform: uppercase;
    }
    .menu_logo {
    	float: left;
    	font-size: 18px;
    }
    a.logotyp, a.logotyp:visited {
    	color: white;
    	transition: .1s;
    	text-decoration: none;
    }
    a.logotyp:hover {
    	color: #a0a0a0;
    }
    
    ul.menuList {
    	list-style-type: none;
    	margin: 0;
    	padding: 0;
    	overflow: hidden;
    }
    
    ul.menuList li.icon {
    	display: none;
    }
    
    ul.menuList li {
    	float: right;
    	display: inline;
    	margin: 0 10px;
    }
    
    ul.menuList li a {
    	color: #a0a0a0;
    	transition: .1s;
    	text-decoration: none;
    }
    ul.menuList li a:hover {
    	color: #e5a000;
    }
    
    /* RESPONSIVE MENU */
    @media screen and (max-width:1000px) {
      ul.menuList li {display: none;}
      ul.menuList li.icon {
        float: right;
        display: inline-block;
      }
    }
    @media screen and (max-width:1000px) {
      ul.menuList.responsive {position: relative;}
      ul.menuList.responsive li.icon {
        position: absolute;
        right: 0;
        top: 0;
      }
      ul.menuList.responsive li {
        float: none;
        display: inline;
      }
      ul.menuList.responsive li a {
        display: block;
        text-align: right;
      }
    }

    <!-- MENU -->
    	<div class="menu_wrapper">
    	
    		<div class="menu_content">
    			
    			<div class="menu_logo">
    				<a href="#top" class="logotyp">&lt;/ECORND></a>
    			</div>
    			
    			<div class="menu_links">
    				<ul class="menuList" id="topnav">
    					<li><a href="#kontakt">Kontakt</a></li>
    					<li><a href="#projekt">projekt</a></li>
    					<li><a href="#tjänster">Tjänster</a></li>
    					<li><a href="#about">info</a></li>
    					<li><a href="#top">hem</a></li>
    					<li class="icon">
    						<a href="javascript:void(0);" style="font-size:15px;" onclick="myFunction()">&#9776;</a>
    					</li>
    				</ul>
    			</div>
    			
    		</div>
    	
    	</div>
&#13;
&#13;
&#13;

但是如果你看一下这个网站,那么下拉列表并没有真正起作用,下拉按钮也没有跟随窗口宽度。我做错了什么?

注意:我从w3school的响应式教程中获得了大部分代码

1 个答案:

答案 0 :(得分:1)

改变这种风格:

ul.menuList li.icon {
    float: right;
}

将以下内容添加到style.css行号:77

ul.menuList li.icon {
   position: fixed;
    right: 15px;
    top: 5px;
}