2017-08-22 94 views
0

隨着代碼下面我想創建一個移動菜單按鈕<container>我的<navigation>裏面。迄今爲止,這一切都很好。移動菜單按鈕不留在導航

但是,不知何故手機菜單按鈕不會留裏面<nav>
(參見相比黃導航綠色容器)

我猜測它有事情做與寬度和高度固定PX。但是,當我將它們更改爲%寬度時,條形圖會完全消失。

我需要更改我的代碼,所以<container>仍然在周圍<nav>

您也可以找到我的代碼here

body { 
 
    margin: 0; 
 
} 
 

 
.header { 
 
    width: 80%; 
 
    height: 10%; 
 
    margin-left: 10%; 
 
    display: flex; 
 
    justify-content: space-between; 
 
    position: fixed; 
 
    top: 0; 
 
    box-sizing: border-box; 
 
    border-style: solid; 
 
    border-width: 1px; 
 
    background-color: yellow; 
 
} 
 

 
.navigation { 
 
    width: 100%; 
 
    height: 100%; 
 
    box-sizing: border-box; 
 
    border-style: solid; 
 
    border-width: 1px; 
 
} 
 

 
.container { 
 
display: inline-block; 
 
cursor: pointer; 
 
float: right; 
 
box-sizing: border-box; 
 
border-style: solid; 
 
border-width: 1px; 
 
background-color: green; 
 
} 
 

 
.bar1, .bar2, .bar3 { 
 
width: 35px; 
 
height: 5px; 
 
background-color: #333; 
 
margin: 6px 0; 
 
transition: 0.4s; 
 
}
<div class="header"> \t 
 
    <nav class="navigation"> 
 
    <div class="container"> 
 
     <div class="bar1"></div> 
 
     <div class="bar2"></div> 
 
     <div class="bar3"></div> 
 
    </div> \t 
 
    </nav> 
 
</div>

回答

0

取下.headerheight: 10%;,它採取10%高度html

body { 
 
    margin: 0; 
 
} 
 

 
.header { 
 
    width: 80%; 
 
    /* height: 10%; */ 
 
    margin-left: 10%; 
 
    display: flex; 
 
    justify-content: space-between; 
 
    position: fixed; 
 
    top: 0; 
 
    box-sizing: border-box; 
 
    border-style: solid; 
 
    border-width: 1px; 
 
    background-color: yellow; 
 
} 
 

 
.navigation { 
 
    width: 100%; 
 
    height: 100%; 
 
    box-sizing: border-box; 
 
    border-style: solid; 
 
    border-width: 1px; 
 
} 
 

 
.container { 
 
display: inline-block; 
 
cursor: pointer; 
 
float: right; 
 
box-sizing: border-box; 
 
border-style: solid; 
 
border-width: 1px; 
 
background-color: green; 
 
} 
 

 
.bar1, .bar2, .bar3 { 
 
width: 35px; 
 
height: 5px; 
 
background-color: #333; 
 
margin: 6px 0; 
 
transition: 0.4s; 
 
}
<div class="header"> \t 
 
    <nav class="navigation"> 
 
    <div class="container"> 
 
     <div class="bar1"></div> 
 
     <div class="bar2"></div> 
 
     <div class="bar3"></div> 
 
    </div> \t 
 
    </nav> 
 
</div>

+0

嗨阿布舍克,非常感謝您的回答。我還在這裏找到了響應式解決方案:https://jsfiddle.net/p6dqLLj6/16/。我目前無法完成的唯一的事情就是移動菜單按鈕以垂直對齊方式出現。 – Michi

0

酒吧和酒吧本身的邊距設置太高。試試下面的CSS

.bar1, .bar2, .bar3 { 
    width: 35px; 
    height: 1px; 
    background-color: #333; 
    margin: 3px 0; 
    transition: 0.4s; 
}