2017-04-23 133 views
0

我正在做移動首先設計,並與CSS和jQuery我做了一個下拉漢堡菜單,我真的很喜歡,但我想要做的是使該漢堡離開時,頁面將顯示在桌面上,並替換爲常規的水平導航欄。我能夠使菜單響應,所以至少有一個水平導航欄在桌面上下降(而不是像手機上的長菜單列表),但我不希望它下降 - 我希望它完全取代漢堡包圖標。我不知道Bootstrap(我是新手),但任何使用html,css和jQuery的建議都會很棒!謝謝!移動時顯示漢堡菜單其他桌面導航欄

這裏是我的代碼:

HTML:

<!DOCTYPE html> 

<html lang="en"> 

<head> 
<meta charset="utf-8"> 
<script src="http://www.google.com/jsapi" type="text/javascript"></script> 
<script type="text/javascript">google.load("jquery", "1.3.2");</script> 
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 

<title>hamburgers</title> 
</head> 

<body> 
    <header> 

    <span>Shine Design</span> 
    <div id="nav-icon4"> 
     <span></span> 
     <span></span> 
     <span></span> 
    </div> 

    </header> 

    <div class="menu"> 
    <ul> 
     <a href="#"> 
     <li>LINK ONE</li> 
     </a> 
     <a href="#"> 
     <li>LINK TWO</li> 
     </a> 
     <a href="#"> 
     <li>LINK THREE</li> 
     </a> 
     <a href="#"> 
     <li>LINK FOUR</li> 
     </a> 
     <a href="#"> 
     <li>LINK FIVE</li> 
     </a> 
    </ul> 
    </div> 

    </body> 
</html> 

JS:

$(document).ready(function(){ 
    $('#nav-icon4').click(function(){ 
    $(this).toggleClass('open'); 
    }); 
}); 

CSS:

@media only screen and (min-width: 300px) { 
    #nav-icon4 { 
    width: 35px; 
    height: 25px; 
    float: right; 
    margin-top: 15px; 
    margin-right: 30px; 
    -webkit-transform: rotate(0deg); 
    -moz-transform: rotate(0deg); 
    -o-transform: rotate(0deg); 
    transform: rotate(0deg); 
    -webkit-transition: .5s ease-in-out; 
    -moz-transition: .5s ease-in-out; 
    -o-transition: .5s ease-in-out; 
    transition: .5s ease-in-out; 
    cursor: cell; 
} 

#nav-icon4 span { 
display: block; 
position: absolute; 
height: 5px; 
width: 100%; 
background: darkred; 
border-radius: 7px; 
opacity: 2; 
left: 0; 
-webkit-transform: rotate(0deg); 
-moz-transform: rotate(0deg); 
-o-transform: rotate(0deg); 
transform: rotate(0deg); 
-webkit-transition: .25s ease-in-out; 
-moz-transition: .25s ease-in-out; 
-o-transition: .25s ease-in-out; 
transition: .25s ease-in-out; 
} 

#nav-icon4 span:nth-child(1) { 
top: 0px; 
-webkit-transform-origin: left center; 
-moz-transform-origin: left center; 
-o-transform-origin: left center; 
transform-origin: left center; 
} 

#nav-icon4 span:nth-child(2) { 
top: 10px; 
-webkit-transform-origin: left center; 
-moz-transform-origin: left center; 
-o-transform-origin: left center; 
transform-origin: left center; 
} 

#nav-icon4 span:nth-child(3) { 
top: 20px; 
-webkit-transform-origin: left center; 
-moz-transform-origin: left center; 
-o-transform-origin: left center; 
transform-origin: left center; 
} 

#nav-icon4.open span:nth-child(1) { 
-webkit-transform: rotate(45deg); 
-moz-transform: rotate(45deg); 
-o-transform: rotate(45deg); 
transform: rotate(45deg); 
top: 0; 
left: 6px; 
} 

#nav-icon4.open span:nth-child(2) { 
width: 0%; 
opacity: 0; 
} 

#nav-icon4.open span:nth-child(3) { 
-webkit-transform: rotate(-45deg); 
-moz-transform: rotate(-45deg); 
-o-transform: rotate(-45deg); 
transform: rotate(-45deg); 
top: 25px; 
left: 6px; 
} 

body { 
    font-family: 'Noto Sans', sans-serif; 
    margin: 0; 
    width: 100%; 
    height: 100vh; 
    background: #ffffff; 
    background-color: black; 
    -webkit-font-smoothing: antialiased; 
    -moz-osx-font-smoothing: grayscale; 
} 

header { 
    width: 100%; 
    background: #ffffff; 
    position: fixed; 
    height: 60px; 
    line-height: 60px; 
    border-bottom: 1px solid #dddddd; 
    display: inline-block; 
    font-size: 2.1em; 
    padding-left: 10px; 
} 

.menu { 
    z-index: 1000000; 
    display: none; 
    font-weight: bold; 
    font-size: 1.2em; 
    width: 100%; 
    background: #f1f1f1; 
    position: fixed; 
    margin-top: 60px; 
    text-align: center; 
    color: black; 
} 

.menu ul { 
    margin: 0; 
    padding: 0; 
    list-style-type: none; 
    list-style-image: none; 
    border-top: #dddddd 1px solid; 
} 

.menu li { 
    display: block; 
    padding: 15px 0 15px 0; 
    border-bottom: #dddddd 1px solid; 
} 

.menu li:hover { 
    display: block; 
    background: #585858; 
    padding: 15px 0 15px 0; 
    border-bottom: #dddddd 1px solid; 
    cursor: crosshair; 
} 

.menu ul li a { 
    text-decoration: none; 
    margin: 0px; 
    color: black; 
} 

.menu ul li a:hover { 
    color: white; 
    text-decoration: none; 
} 

.menu a { 
    text-decoration: none; 
    color: black; 
} 

.menu a:hover { 
    text-decoration: none; 
    color: white; 
    } 
} 


@media only screen and (min-width: 601px) {  
    header { 
    font-size: 1.5em; 
} 

    ul { 
    list-style-type: none; 
    margin: 0; 
    padding: 0; 
    overflow: hidden; 
} 

    li { 
    float: right; 
    margin-left: 15px; 
    margin-right: 25px; 
} 

    li a { 
    display: block; 
    text-align: center; 
    padding: 14px 16px; 
    text-decoration: none; 
} 
.menu { 
    font-size: .8em; 
    } 
} 

回答

1

你要更新你的CSS展現漢堡按鈕在你想要的斷點處在...處可見。

目前,您已將其設置爲顯示在(min-width: 300px),但看起來您的導航將成爲601px的大屏幕視圖。所以你只想讓你的漢堡包在601px處也不顯示。

雖然上一個單獨的說明,我看你已經構建了您的漢堡這樣:

<div id="nav-icon4"> 
    <span></span> 
    <span></span> 
    <span></span> 
</div> 

我會強烈建議你修改這個代碼如下:

<button type="button" id="nav-icon4" aria-label="Menu"> 
    <span></span> 
    <span></span> 
    <span></span> 
</button> 

這樣做所以,鍵盤用戶可以訪問該按鈕。

+0

謝謝我會讓它無障礙! :) – SShine2

+0

添加顯示器沒有工作,這是真棒和邁向正確的方向一步,但我怎麼讓我的導航欄顯示在它的位置? – SShine2

+0

您需要將其設置爲在最小寬度601媒體查詢中顯示塊。 我已經做了一個快速演示,有一些小的修改自己的代碼,向您展示 https://codepen.io/scottohara/pen/EmyRBj 好運與此 – scottohara

0

如果你的新手,幫你一個忙,並學習引導,它使這種事情非常簡單,並阻止你嚴重重新發明車輪。

開始看這裏... https://getbootstrap.com/examples/navbar/這裏:https://getbootstrap.com/components/#navbar

要做到你想要什麼,你將需要設置CSS媒體查詢正確的顯示。這正是bootstrap所做的,所以如果你堅持自己做這件事,那麼首先要了解關於媒體斷點的知識。

/* Custom, iPhone Retina */ 
@media only screen and (min-width : 320px) { 

} 

/* Extra Small Devices, Phones */ 
@media only screen and (min-width : 480px) { 

} 

/* Small Devices, Tablets */ 
@media only screen and (min-width : 768px) { 

} 

/* Medium Devices, Desktops */ 
@media only screen and (min-width : 992px) { 

} 

/* Large Devices, Wide Screens */ 
@media only screen and (min-width : 1200px) { 

} 
+0

我一定會接受這個建議並做一些閱讀,因爲我被教會先編碼手機。儘管如此,媒體的詢問對我來說非常混亂。我理解這個概念,但有時我無法實現它的工作方式。 – SShine2

相關問題