2016-11-09 35 views
3

我的手机css汉堡包菜单无法正常工作,如果点击它,它不会保持打开状态,我不知道如何打开汉堡菜单内的下拉菜单。另外我的导航标题(.logo)很难居中,有没有人有解决方案?我的手机css无法正常工作

JSFidlle for easy viewability(移动CSS &的style.css在这里被合并只是背景丢失)

感谢您的帮助,并抱歉,如果我的代码看起来杂乱无章:/

我的代码:

index.html文件

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>Hello, I'm Sten</title> 
    <link rel="stylesheet" href="css/style.css"> 
    <link rel="stylesheet" href="css/mobile.css"> 
    <link rel="stylesheet" href="css/animate.css"> 
</head> 
<body> 
    <div class="nav animated slideInDown"> 
     <img src="img/hamburger.png" alt="" class="hamburger"> 
     <div class="logo"> 
      <h1>STEN</h1> 
     </div> 
     <ul> 
      <li> 
       <a href="#">PAGE</a> 
       <ul> 
        <li><a href="#">DROPDOWN</a></li> 
        <li><a href="#">DROPDOWN</a></li> 
       </ul> 
      </li> 
      <li><a href="#">PAGE</a></li> 
      <li><a href="#">PAGE</a></li> 
      <li><a href="#">PAGE</a></li> 
     </ul> 
    </div> 

    <div class="landing animated fadeIn"> 
     <div class="container"> 
      <h1>STEN</h1> 
      <hr> 
      <p>I'M A</p> 
      <h2>-OCCUPATION-</h1> 
      <button>KNOP</button> 
      <button>KNOP</button> 
     </div> 
     <div class="scroll" onClick=""> 

     </div> 
    </div> 

    <div class="about"> 

    </div> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
    <script scr="main.js"></script> 
</body> 
</html> 

的style.css(主css文件)

* { 
    padding: 0; 
    margin: 0; 
    border: 0; 
} 

html, body { 
    height: 100%; 
    width: 100%; 
    font-family: 'Open Sans', sans-serif; 
} 

h1 { 
    font-weight: 300; 
    font-size: 50px; 
} 

.nav { 
    width: 100%; 
    height: 10%; 
    background-color: #F2F2F2; 
    border-bottom: 1px solid #E4E4E4; 
    text-align: center; 
    position: fixed; 
    z-index: 999; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); 
} 

.nav .hamburger { 
    display: none; 
} 

.nav .logo { 
    float: left; 
    margin-left: 10%; 
} 

.nav .logo h1 { 
    color: #000; 
    line-height: 10vh; 
    font-size: 32px; 
} 

.nav > ul { 
    height: 100%; 
    width: auto !important; 
    display: inline-block; 
    float: right; 
    margin-right: 10%; 

} 

.nav > ul > li { 
    display: inline-block; 
    list-style: none; 
    padding: 0 20px 0 20px; 
    vertical-align: top; 
    position: relative; 
} 

.nav > ul > li:first-child > a:after { 
    width: 6px; 
    height: 6px; 
    border-bottom: 1px solid #000; 
    border-right: 1px solid #000; 
    position: absolute; 
    margin-top: calc(5vh - 5px); 
    margin-left: 8px; 
    content: ""; 
    transform: rotate(45deg); 
} 

.nav > ul > li > ul { 
    display: none; 
    margin-left: -50%; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); 
} 

.nav > ul > li > ul > li { 
    list-style: none; 
    background-color: #F2F2F2; 
    padding: 0 20px 0 20px; 
    position: relative; 
} 

.nav li:hover > ul { 
    display: block; 
    position: absolute; 
} 

.nav ul a { 
    color: #000; 
    text-decoration: none; 
    line-height: 10vh; 
} 

.nav a:hover { 
    color: #999; 
} 

.landing { 
    padding-top: 10vh; 
    height: 90%; 
    width: 100%; 
    background: url('../img/bg.jpg'); 
    background-size: cover; 
    background-position: center; 
    position: fixed; 
    text-align: center; 
    color: #FFF; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); 
    z-index: 0; 
} 

.landing:before { 
    content: " "; 
    position: absolute; 
    height: 100%; 
    width: 100%; 
    top: 0; 
    left: 0; 
    background-color: rgba(0, 0, 0, 0.4); 
} 

.landing .container { 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    -moz-transform: translateX(-50%) translateY(-50%); 
    -webkit-transform: translateX(-50%) translateY(-50%); 
    transform: translateX(-50%) translateY(-50%); 
    width: 100%; 
} 

.landing .container h1 { 
    letter-spacing: 6px; 
    font-size: 78px; 
} 

.landing .container p { 
    font-size: 20px; 
    font-weight: 100; 
} 

.landing hr { 
    width: 300px; 
    margin: 25px 0 25px 0; 
    margin-left: calc(50% - 150px); 
    border-bottom: 3px solid #EF2D56; 
} 

.landing button { 
    width: 200px; 
    padding: 24px; 
    margin-top: 20px; 
    position: relative; 
    color: #FFF; 
    background-color: transparent; 
    border: 1px solid #FFF; 
} 

.landing button:first-child { 
    margin-right: 1%; 
} 

.landing button:last-child { 
    margin-left: 1%; 
    background-color: #EF2D56; 
    border: 1px solid #EF2D56; 
} 

.landing button:hover { 
    cursor: pointer; 
} 

.landing button:focus { 
    outline: none; 
} 

.scroll { 
    width: 16px; 
    height: 16px; 
    border-bottom: 1px solid #FFF; 
    border-right: 1px solid #FFF; 
    position: absolute; 
    content: " "; 
    transform: rotate(45deg); 
    bottom: 0; 
    margin-bottom: 30px; 
    margin-left: calc(50% - 8px); 
    cursor: pointer; 
} 

.about { 
    height: 200%; 
    width: 100%; 
    background-color: #FFF;; 
    z-index: 50; 
    position: absolute; 
    margin-top: 100vh; 
} 

移动css文件

​​
+0

这似乎需要一个'hover',因为你不能用手指悬停(至少,而不是设备可读的方式),它不会保持打开状态。 – DBS

回答

1

更改你写媒体查询的方式,试试这个方法:

@media only screen and (max-width: 850px) { 
    //Your mobile CSS code 
} 

见琴:https://jsfiddle.net/7xjyutuf/1/

+0

这可以修复一些问题,但汉堡菜单仍然不是静态的,点击后会消失。 – Sten

+0

你能解释一下你期待汉堡包应该怎样工作吗? –

+0

如果我点击chrome上的汉堡菜单,导航会显示,但是当我尝试点击链接时,它会消失。我希望它留在那里,所以我可以点击一个链接。 而一个小问题是我需要在导航内的下拉菜单下降,我不知道该怎么做。 – Sten

1

chnage媒体查询到这个@media only screen and (max-width:850px){}

  1. 如果您使用的是max-device-width,当你改变浏览器窗口的大小在桌面上,CSS样式不会改变不同的媒体查询设置;
  2. 如果您使用max-width,当您更改桌面上浏览器的大小时,CSS将更改为不同的媒体查询设置,并且可能会显示移动设备的样式,例如触摸式菜单。

获取更多信息,您可以访问这个http://www.menucool.com/3613/max-device-width-vs-max-width-Which-one-should-I-use

检查此琴https://jsfiddle.net/ok7hmodo/1/

为了使菜单使用静态检查Jquery.Please这https://jsfiddle.net/7xjyutuf/10/

这是一个CSS只solution.You必须做出UL显示块当用户将鼠标悬停在其上 https://jsfiddle.net/tucsgohy/1/

+0

我把它改成了最大宽度,测试起来更容易,但它不能解决我的主要问题;汉堡菜单仍然不是静态的 – Sten

+0

检查这对你是否正常https://jsfiddle.net/7xjyutuf/10/ – XYZ

+0

https://jsfiddle.net/tucsgohy/1/ – XYZ