2016-04-25 64 views
0

我試圖修復我的菜單代碼,以便當我將鼠標懸停在按鈕上時,下拉菜單將與按鈕的左邊緣一致。現在它像列表一樣向右間隔一點。如何將菜單下拉內容移動到與按鈕的左邊緣一致?

HTML:

<center> 
    <div class="menubar"> 
     <button class="button">Forms 
     <div class="menubar-content"> 
     <a href="#">Department Update Form</a> 
     <a href="#">Project Start Month Form</a> 
     <a href="#">Add New Employee Form</a> 
     </div> 
     </button> 
     <button class="button">Reports 
     <div class="menubar-content"> 
     <a href="#">Human Resource's Employees Report</a> 
     </div> 
     </button> 
     <button class="button">Reports 
     <div class="menubar-content"> 
     <a href="#">Human Resource's Employees Report</a> 
     <a href="#">2012 04 Product Plan Project Report</a> 
     <a href="#">Department Data Report</a> 
     <a href="#">Employee Business Info Report</a> 
     <a href="#"></a> 
     </div> 
     </button> 
    </div> 
</center> 

CSS:

.button { 
background-color: blue; 
color: white; 
padding: 16px; 
font-size: 16px; 
border: none; 
cursor: pointer; 
margin:5px; 
} 

.menubar { 
    position: relative; 
    display: inline-block; 
} 

.menubar-content { 
    display: none; 
    position: absolute; 
    background-color: #f9f9f9; 
    min-width: 200px; 
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); 
    margin: 16px; 
} 

.menubar-content a { 
    color: black; 
    padding: 12px 16px; 
    text-decoration: none; 
    display: block; 
} 

.menubar-content a:hover { 
    background-color: #f1f1f1; 
} 

.button:hover .menubar-content { 
    display: block; 

} 

.menubar:hover .dropbtn { 
    background-color: #3e8e41; 
} 

回答

0

它響應你的按鈕,因爲它是<button>標籤內的填充。所以你只需要在div上加一個負值就可以了。

.menubar-content { 
    display: none; 
    position: absolute; 
    background-color: #f9f9f9; 
    min-width: 200px; 
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); 
    margin: 16px; 
    margin-left: -16px; //add this line 
} 
+1

非常感謝!我從來沒有這樣做過。 – Jeremy

+1

沒有問題。如果能夠工作,你是否介意接受我的答案是正確的,以幫助後來發現此問題的人? – amflare

+2

當然!儘管如此,您在保證金餘額後錯過了冒號。別擔心。 – Jeremy