2016-03-30 207 views
2

我有這個下拉菜單,爲我的移動網站。問題是,點擊下拉菜單之外時,它不會消失。所以當點擊按鈕時,除了從菜單中選擇其他網站之外,沒有辦法再次擺脫菜單。當它顯示時,是否有可能在點擊它之外時讓它消失?移動下拉菜單不會消失

這是我的代碼:

/* Dropdown Button */ 
 
.dropbtn { 
 
    background-color: #948a69; 
 
    color: white; 
 
    padding: 16px; 
 
    font-size: 16px; 
 
    border: none; 
 
    cursor: pointer; 
 
} 
 

 
/* The container <div> - needed to position the dropdown content */ 
 
.dropdown { 
 
    position: relative; 
 
    display: inline-block; 
 
} 
 

 
/* Dropdown Content (Hidden by Default) */ 
 
.dropdown-content { 
 
    display: none; 
 
    position: absolute; 
 
    background-color: #f9f9f9; 
 
    min-width: 160px; 
 
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); 
 
} 
 

 
/* Links inside the dropdown */ 
 
.dropdown-content a { 
 
    color: black; 
 
    padding: 12px 16px; 
 
    text-decoration: none; 
 
    display: block; 
 
} 
 

 
/* Change color of dropdown links on hover */ 
 
.dropdown-content a:hover {background-color: #f1f1f1} 
 

 
/* Show the dropdown menu on hover */ 
 
.dropdown:hover .dropdown-content { 
 
    display: block; 
 
} 
 

 
/* Change the background color of the dropdown button when the dropdown content is shown */ 
 
.dropdown:hover .dropbtn { 
 
    background-color: #9e9370; 
 
}
<div style="position:absolute; top:15px; left:15px;"> 
 
<div class="dropdown"> 
 
    <button class="dropbtn"><b>MENU</b></button> 
 
    <div class="dropdown-content"> 
 
    <a href="index.html">Velkommen</a> 
 
    <a href="bock.html">Produkter</a> 
 
    <a href="fadol.html">Fadøl</a> 
 
    <a href="historie.html">Historie</a> 
 
    <a href="kontakt.html">Kontakt </a> 
 
    </div> 
 
</div> 
 
</div>

回答

0

我有同樣的問題,並發現從這裏的解決方案:
http://www.cssplay.co.uk/menus/cssplay-ipad-dropdown-menu-fixed.html

周圍使用透明圖像的修復中心強制我們想要的瀏覽器行爲。你最後</div>

// For the Safari mobile browser 
div img.close { 
    display: none; 
    width: 100%; 
    height: 100%; 
    position: fixed; 
    left: 0; 
    top: 0; 
    z-index: -1; 
} 

div button:hover + img { 
    display: block; 
} 

然後在你的HTML添加此,:添加這個CSS

<img class="close" src="ipad/trans.gif" /> 

我個人使用這個處理列表,而不是按鈕,所以可能有一些必要的調整。但我可以確認它使用列表(基於<ul><li>的菜單)。