2016-11-09 69 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