html - 响应式菜单问题

标签 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>

但是如果您查看该站点,下拉菜单实际上并没有任何用处,而且下拉按钮没有跟随窗口宽度。我做错了什么?

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

最佳答案

更改此样式:

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

将下面添加到 style.css 第 77 行

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

关于html - 响应式菜单问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41034793/

相关文章:

html - CSS 适用于在 firefox 中工作的 aspx 页面,但不适用于 IE。只有 1 个按钮的样式不起作用。有任何想法吗?

java - org.xml.sax.SAXParseException : Reference is not allowed in prolog

javascript - 在 jquery 移动页面中添加面板会使设备上的页面滚动卡住

css - 元素 "top"在较小的视口(viewport)宽度(<835 像素)上发生变化

html - 如果元素内的内容可以将其扩展到超出其分配范围,那么 CSS Grid 中的 fr 单位有什么意义

html - 为什么在移动版全屏背景图像模糊?

html - 使用 Google Fonts 为每种字体请求不同的字符?

javascript - .stop(true) 似乎并没有真正清除队列?

html - 两个并排的 Div - 增加响应能力

html - 使用 CSS flex 的两个全高页面